-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxconf_test.js
58 lines (40 loc) · 1.13 KB
/
maxconf_test.js
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
var os = require('os');
var fs = require('fs');
var path = require('path');
var tape = require('tape');
var assert = require('assert');
// this must be set prior to requiring maxconf
process.env.HOME = os.tmpDir();
var maxconf = require('./maxconf');
var testOpts = {
file: './sample.maxcdn.yml'
};
var tmpDefault = path.join(process.env.HOME, '.maxcdn.yml');
function setup() {
fs.writeFileSync(tmpDefault, fs.readFileSync(testOpts.file));
}
function teardown() {
fs.unlink(tmpDefault);
}
tape('maxconf.js', function (test) {
setup();
test.plan(6);
var config;
// with default
config = maxconf();
test.equal(config.alias, 'YOUR_ALIAS');
// with object
config = maxconf(testOpts);
test.equal(config.alias, 'YOUR_ALIAS');
// with string
config = maxconf(testOpts.file);
test.equal(config.alias, 'YOUR_ALIAS');
testOpts.alias = 'ALIAS_OVERIDE';
config = maxconf(testOpts);
test.equal(config.alias, 'ALIAS_OVERIDE');
maxconf(testOpts, function (err, config) {
test.error(err);
test.equal(config.token, 'YOUR_TOKEN');
teardown();
});
});