Skip to content

Commit

Permalink
Merge pull request #8 from dopecodez/develop
Browse files Browse the repository at this point in the history
Merging tests to master
  • Loading branch information
dopecodez committed Jun 14, 2020
2 parents 4f8a89c + dbf08b0 commit 0c7f821
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
log.txt
2 changes: 1 addition & 1 deletion src/builder/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const linux = (ip: string, options?: extendedPingOptions): commandBuilder => {
if (options?.floodPing) {
if (typeof options?.interval === 'number') {
args.push('-i', options?.interval.toString())
emitWarning(ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
} else {
args.push('-f');
emitWarning(ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
}
}
if (typeof options?.interfaceAddress === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/builder/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const mac = (ip: string, options?: extendedPingOptions): commandBuilder => {
if (typeof options?.TTL === 'number') {
args.push('-m', options.TTL.toString()); //change to -t for linux
}
if (typeof options?.doNotFragment === 'number') {
if (options.doNotFragment) {
args.push('-D');
}
if (options?.numeric) {
Expand Down
79 changes: 69 additions & 10 deletions test/builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,55 @@ const sampleBuildCommands = {
},
WIN_GENERAL_ARGS: {
command: process.env.SystemRoot + '/system32/ping.exe',
arguments: ['127.0.0.1', '-n', '6', '-w', '2000']
arguments: ['127.0.0.1', '-n', '6', '-l', '52', '-i', '2000', '-w', '2000']
},
WIN_GENERAL_ARGS_NO_PROTOCOL: {
command: process.env.SystemRoot + '/system32/ping.exe',
arguments: ['127.0.0.1', '-n', '6',]
},
WIN_IPV4_ARGS: {
command: process.env.SystemRoot + '/system32/ping.exe',
arguments: ['127.0.0.1', '-n', '6', '-w', '2000', '-4', '-f']
arguments: ['127.0.0.1', '-4', '-f', '-r', '5', '-s', '5000']
},
WIN_IPV6_ARGS: {
command: process.env.SystemRoot + '/system32/ping.exe',
arguments: ['127.0.0.1', '-6', '-S', 'testAddress']
},
MAC_NO_ARGS: {
command: '/sbin/ping',
arguments: ['127.0.0.1', '-c', '4']
},
MAC_GENERAL_ARGS: {
command: '/sbin/ping',
arguments: ['127.0.0.1', '-c', '6', '-n', '-t', '10', '-W', '2000']
arguments: ['127.0.0.1', '-c', '6', '-d', '-f', '-n', '-t', '10', '-W', '2000']
},
MAC_EXTENDED_ARGS: {
command: '/sbin/ping',
arguments: ['127.0.0.1', '-c', '6', '-i', '100', '-I', 'testInterface', '-L', '-m', '3000']
},
MAC_EXTENDED_ARGS2: {
command: '/sbin/ping',
arguments: ['127.0.0.1', '-c', '6', '-D', '-n', '-p', 'test', '-q', '-S', 'testAddr']
},
MAC_EXTENDED_ARGS3: {
command: '/sbin/ping',
arguments: ['127.0.0.1', '-c', '6', '-s', '52', '-v']
},
LINUX_NO_ARGS: {
command: 'ping',
arguments: ['127.0.0.1', '-c', '4']
},
LINUX_GENERAL_ARGS: {
command: 'ping',
arguments: ['127.0.0.1', '-c', '6', '-n', '-W', '10', '-w', '2']
arguments: ['127.0.0.1', '-c', '6', '-d', '-f', '-n', '-W', '10', '-w', '2']
},
LINUX_EXTENDED_ARGS: {
command: 'ping',
arguments: ['127.0.0.1', '-c', '6', '-i', '100', '-I', 'testAddr', '-L', '-t', '1000']
},
LINUX_EXTENDED_ARGS2: {
command: 'ping',
arguments: ['127.0.0.1', '-c', '6', '-n', '-p', 'testPattern', '-q', '-s', '52', '-v']
},
MAC_IPV6_ARGS: {
command: '/sbin/ping6',
Expand All @@ -46,18 +74,23 @@ test('Check if builder creates command arguments corerectly for windows', t => {
})

test('Check if builder creates general command arguments corerectly for windows', t => {
let command = createBuilder('127.0.0.1', 'win32', { numberOfEchos: 6, timeout: 2 });
let command = createBuilder('127.0.0.1', 'win32', { numberOfEchos: 6, timeout: 2, TTL: 2000, bufferSize: 52 });
t.deepEqual(command, sampleBuildCommands.WIN_GENERAL_ARGS);
})

test('Check if builder creates IPV4 command arguments corerectly for windows', t => {
let command = createBuilder('127.0.0.1', 'win32', { numberOfEchos: 6, timeout: 2, IPV4: true, doNotFragment: true });
let command = createBuilder('127.0.0.1', 'win32', { IPV4: true, doNotFragment: true, recordRouteHops: 5, hopTimestamp: 5000 });
t.deepEqual(command, sampleBuildCommands.WIN_IPV4_ARGS);
})

test('Check if builder creates general command without explicit protocol metioned for windows', t => {
let command = createBuilder('127.0.0.1', 'win32', { numberOfEchos: 6, timeout: 2, doNotFragment: true });
t.deepEqual(command, sampleBuildCommands.WIN_GENERAL_ARGS);
let command = createBuilder('127.0.0.1', 'win32', { numberOfEchos: 6, doNotFragment: true });
t.deepEqual(command, sampleBuildCommands.WIN_GENERAL_ARGS_NO_PROTOCOL);
})

test('Check if builder creates IPV6 args for windows', t => {
let command = createBuilder('127.0.0.1', 'win32', { IPV6: true, srcAddr: 'testAddress' });
t.deepEqual(command, sampleBuildCommands.WIN_IPV6_ARGS);
})

test('Check if builder creates command arguments corerectly for mac', t => {
Expand All @@ -66,20 +99,46 @@ test('Check if builder creates command arguments corerectly for mac', t => {
})

test('Check if builder creates general command arguments corerectly for mac', t => {
let command = createBuilder('127.0.0.1', 'darwin', { numberOfEchos: 6, timeout: 2, numeric: true, timeBeforeExit: 10 });
let command = createBuilder('127.0.0.1', 'darwin', { numberOfEchos: 6, timeout: 2, numeric: true, timeBeforeExit: 10, soDebugOption: true, floodPing: true });
t.deepEqual(command, sampleBuildCommands.MAC_GENERAL_ARGS);
})

test('Check if builder creates extended command arguments corerectly for mac 1', t => {
let command = createBuilder('127.0.0.1', 'darwin', { numberOfEchos: 6, interval: 100, interfaceAddress: 'testInterface', suppressLoopback: true, TTL: 3000 });
t.deepEqual(command, sampleBuildCommands.MAC_EXTENDED_ARGS);
})

test('Check if builder creates extended command arguments corerectly for mac 2', t => {
let command = createBuilder('127.0.0.1', 'darwin', { numberOfEchos: 6, doNotFragment: true, numeric: true, pattern: 'test', quiet: true, srcAddr: 'testAddr' });
t.deepEqual(command, sampleBuildCommands.MAC_EXTENDED_ARGS2);
})

test('Check if builder creates extended command arguments corerectly for mac 3', t => {
let command = createBuilder('127.0.0.1', 'darwin', { numberOfEchos: 6, bufferSize: 52, verboseOutput: true });
t.deepEqual(command, sampleBuildCommands.MAC_EXTENDED_ARGS3);
})

test('Check if builder creates command arguments corerectly for linux', t => {
let command = createBuilder('127.0.0.1', 'linux');
t.deepEqual(command, sampleBuildCommands.LINUX_NO_ARGS);
})

test('Check if builder creates general command arguments corerectly for linux', t => {
let command = createBuilder('127.0.0.1', 'linux', { numberOfEchos: 6, timeout: 2, numeric: true, timeBeforeExit: 10 });
let command = createBuilder('127.0.0.1', 'linux', { numberOfEchos: 6, timeout: 2, numeric: true, timeBeforeExit: 10, soDebugOption: true, floodPing: true });
t.deepEqual(command, sampleBuildCommands.LINUX_GENERAL_ARGS);
})

test('Check if builder creates extended command arguments corerectly for linux', t => {
let command = createBuilder('127.0.0.1', 'linux', { numberOfEchos: 6, interval: 100, interfaceAddress: 'testAddr', suppressLoopback: true, TTL: 1000});
t.deepEqual(command, sampleBuildCommands.LINUX_EXTENDED_ARGS);
})

test('Check if builder creates extended command arguments corerectly for linux 2', t => {
let command = createBuilder('127.0.0.1', 'linux', { numberOfEchos: 6, numeric: true, pattern: 'testPattern', quiet: true, bufferSize: 52, verboseOutput: true });
t.deepEqual(command, sampleBuildCommands.LINUX_EXTENDED_ARGS2);
})


test('Check if builder creates ping6 command for mac systems', t => {
let command = createBuilder('127.0.0.1', 'darwin', { IPV6: true });
t.deepEqual(command, sampleBuildCommands.MAC_IPV6_ARGS);
Expand Down
15 changes: 6 additions & 9 deletions test/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ test('Check if log file is created without logging enabled', t => {
t.is(log.enabledLogging, false)
})

//TO-DO : Find out why this causes travis.yml to fail
// test('Check if log file is created and can be written to', async t => {
// const log = new logger('log.txt', true);
// const testData = 'Test'
// await log.writeToLogFile(testData);
// let exists = fs.existsSync('log.txt');
// t.is(exists, true);
// fs.unlinkSync('log.txt');
// });
test('Check if log file is created and can be written to', async t => {
const log = new logger('log.txt', true);
const testData = 'Test';
await log.writeToLogFile(testData);
t.is(log.enabledLogging, true);
});

0 comments on commit 0c7f821

Please sign in to comment.