corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 var test = require('tap').test
2 var CC = require('../index.js').ConfigChain
3  
4 var env = { foo_blaz : 'blzaa', foo_env : 'myenv' }
5 var jsonObj = { blaz: 'json', json: true }
6 var iniObj = { 'x.y.z': 'xyz', blaz: 'ini' }
7  
8 var fs = require('fs')
9 var ini = require('ini')
10  
11 fs.writeFileSync('/tmp/config-chain-class.json', JSON.stringify(jsonObj))
12 fs.writeFileSync('/tmp/config-chain-class.ini', ini.stringify(iniObj))
13  
14 var http = require('http')
15 var reqs = 0
16 http.createServer(function (q, s) {
17 if (++reqs === 2) this.close()
18 if (q.url === '/json') {
19 // make sure that the requests come back from the server
20 // out of order. they should still be ordered properly
21 // in the resulting config object set.
22 setTimeout(function () {
23 s.setHeader('content-type', 'application/json')
24 s.end(JSON.stringify({
25 blaz: 'http',
26 http: true,
27 json: true
28 }))
29 }, 200)
30 } else {
31 s.setHeader('content-type', 'application/ini')
32 s.end(ini.stringify({
33 blaz: 'http',
34 http: true,
35 ini: true,
36 json: false
37 }))
38 }
39 }).listen(1337)
40  
41 test('basic class test', function (t) {
42 var cc = new CC()
43 var expectlist =
44 [ { blaz: 'json', json: true },
45 { 'x.y.z': 'xyz', blaz: 'ini' },
46 { blaz: 'blzaa', env: 'myenv' },
47 { blaz: 'http', http: true, json: true },
48 { blaz: 'http', http: true, ini: true, json: false } ]
49  
50 cc.addFile('/tmp/config-chain-class.json')
51 .addFile('/tmp/config-chain-class.ini')
52 .addEnv('foo_', env)
53 .addUrl('http://localhost:1337/json')
54 .addUrl('http://localhost:1337/ini')
55 .on('load', function () {
56 t.same(cc.list, expectlist)
57 t.same(cc.snapshot, { blaz: 'json',
58 json: true,
59 'x.y.z': 'xyz',
60 env: 'myenv',
61 http: true,
62 ini: true })
63  
64 cc.del('blaz', '/tmp/config-chain-class.json')
65 t.same(cc.snapshot, { blaz: 'ini',
66 json: true,
67 'x.y.z': 'xyz',
68 env: 'myenv',
69 http: true,
70 ini: true })
71 cc.del('blaz')
72 t.same(cc.snapshot, { json: true,
73 'x.y.z': 'xyz',
74 env: 'myenv',
75 http: true,
76 ini: true })
77 cc.shift()
78 t.same(cc.snapshot, { 'x.y.z': 'xyz',
79 env: 'myenv',
80 http: true,
81 json: true,
82 ini: true })
83 cc.shift()
84 t.same(cc.snapshot, { env: 'myenv',
85 http: true,
86 json: true,
87 ini: true })
88 cc.shift()
89 t.same(cc.snapshot, { http: true,
90 json: true,
91 ini: true })
92 cc.shift()
93 t.same(cc.snapshot, { http: true,
94 ini: true,
95 json: false })
96 cc.shift()
97 t.same(cc.snapshot, {})
98 t.end()
99 })
100 })