-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathutils.js
More file actions
119 lines (88 loc) · 3.03 KB
/
utils.js
File metadata and controls
119 lines (88 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
const assert = require('assert'),
os = require('os'),
utils = require('../src/utils');
describe('utils', function () {
process.env.silent = true;
// Configure timeout = 5 sec.
this.timeout(5000);
describe('fixUrl', () => {
it('null-value', () =>
assert.equal(null, utils.fixUrl(null))
);
it('HTTP scheme', () => {
const URL = 'http://android-arsenal.com';
assert.equal(URL, utils.fixUrl(URL));
});
it('HTTPS scheme', () => {
const URL = 'https://android-arsenal.com';
assert.equal(URL, utils.fixUrl(URL));
});
});
describe('encodeBase64', () => {
it('BASE64 for not empty JSON object', () => {
assert.equal(
'eyJmb3JjZSI6dHJ1ZX0=',
utils.encodeBase64({
'force': true
})
);
});
it('BASE64 for empty JSON object', () =>
assert.equal('e30=', utils.encodeBase64({}))
);
it('BASE64 for null-object', () =>
assert.equal('bnVsbA==', utils.encodeBase64(null))
);
it('BASE64 for non-JSON object', () =>
assert.equal('IlN0cmluZyI=', utils.encodeBase64('String'))
);
});
describe('filePath', () => {
it('not null', () => {
const file = utils.filePath('.');
assert.notEqual(null, file);
assert.notEqual('', file);
});
});
describe('runFsWatchdog', () => {
it('should not start fs watch dog', () => {
assert.equal(null, utils.runFsWatchdog(null, 0, null));
assert.equal(null, utils.runFsWatchdog(null, 60, null));
assert.equal(null, utils.runFsWatchdog('/tmp', 0, null));
});
it('should start fs watch dog correctly', () => {
const watchdog = utils.runFsWatchdog(os.tmpdir(), 1, function () {});
assert.notEqual(null, watchdog);
clearInterval(watchdog);
});
});
describe('execProcess', () => {
it('should not execute empty command', (done) => {
assert.throws(() => utils.execProcess(null, null));
assert.throws(() => utils.execProcess(null, {}));
done();
});
it('execute "ls"', (done) => {
utils.execProcess(['ls'], null, (error1) => {
assert.equal(null, error1);
utils.execProcess(['ls'], {}, (error2) => {
assert.equal(null, error2);
done();
});
});
});
it('execute "ls -l"', (done) => {
utils.execProcess(['ls', '-l'], null, (error) => {
assert.equal(null, error);
done();
});
});
it('execute "ls -l -a"', (done) => {
utils.execProcess(['ls', '-l', '-a'], null, (error) => {
assert.equal(null, error);
done();
});
});
});
});