Commit d65dc2c3 authored by Erik Schwartz's avatar Erik Schwartz 🉐
Browse files

Add code, linter settings, tests

parent d6d2e6aa
node_modules
site-config
{
"extends": "strongloop",
"env": {
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
},
"rules": {
"no-trailing-spaces": "error"
}
}
'use strict';
// -------------------------------------------------------------------------
// Variable definitions
// -------------------------------------------------------------------------
const f = require('./functions');
const options = './site-config/client.json';
// -------------------------------------------------------------------------
// Main logic
// -------------------------------------------------------------------------
f.doIt(options, (err) => {
if (err) {
console.error(err);
}
});
'use strict';
// -------------------------------------------------------------------------
// Variable definitions
// -------------------------------------------------------------------------
const fs = require('fs');
const scp = require('scp2');
// -------------------------------------------------------------------------
// Helper functions
// -------------------------------------------------------------------------
function readSftpOptions(json) {
try {
let o = fs.readFileSync(json);
o = JSON.parse(o);
return o;
} catch (err) {
console.error('Options read error: ' + err);
throw err;
}
}
function downloadFile(opt, f, callback) {
scp.scp(opt, f, (err) => {
if (err) {
return callback(err);
}
return callback();
});
}
// -------------------------------------------------------------------------
// Exported functions
// -------------------------------------------------------------------------
exports.doIt = function(optionsFile, callback) {
let o = readSftpOptions(optionsFile);
let scpOpt = o.remoteSettings;
let outFile = o.localFile;
downloadFile(scpOpt, outFile, (err) => {
if (err) {
return callback(err);
}
return callback();
});
};
{
"name": "recfu-mover",
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"eslint": "^5.7.0",
"eslint-config-strongloop": "^2.1.0",
"mocha": "^5.2.0",
"rewire": "^4.0.1",
"scp2": "^0.5.0"
},
"devDependencies": {},
"scripts": {
"pretest": "eslint --ignore-path .eslintignore .",
"test": "mocha"
},
"author": "whatitis",
"license": "MIT",
"description": "Move files from IQ SFTP server to Rec Sports Windows share",
"repository": {
"type": "git",
"url": "https://git.iq.it.umich.edu/whatitis/nc.git"
}
}
{
"remoteSettings": {
"host": "boo.umich.edu",
"port": "22",
"username": "someguy",
"password": "secret",
"path": "/srv/pickup/great-file.csv"
},
"localFile": "/usr/local/dropoff/great-file.csv"
}
'use strict';
/* eslint-env mocha */
// --------------------------------------------------------------------------
// GLOBAL VAR DEFINITIONS
// --------------------------------------------------------------------------
const assert = require('assert');
const rewire = require('rewire');
const pf = rewire('../functions');
// Map rewired, private functions to friendlier names
const readSftpOptions = pf.__get__('readSftpOptions');
// --------------------------------------------------------------------------
// MOCHA TESTS
// --------------------------------------------------------------------------
describe('Filesystem & JSON parsing integration', function() {
let inFile = './site-config/client.json.EXAMPLE';
describe('Read ' + inFile, function() {
it('should return object with known properties', function() {
let o = readSftpOptions(inFile);
assert.equal(typeof o, 'object');
assert.equal(o.hasOwnProperty('remoteSettings'), true);
assert.equal(o.hasOwnProperty('localFile'), true);
});
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment