1 | should = require 'should'
|
2 | _ = require 'lodash'
|
3 | logger = require 'torch'
|
4 | {join} = require 'path'
|
5 |
|
6 | core = require '../lib/core'
|
7 | mockRetriever = require './helpers/mockRetriever'
|
8 |
|
9 | initCore = (packages) ->
|
10 | retriever = mockRetriever()
|
11 | _.merge retriever.packages, packages
|
12 | core.init {timeout: 20}, retriever
|
13 |
|
14 | describe 'application config', ->
|
15 |
|
16 | afterEach ->
|
17 | core.reset()
|
18 |
|
19 | it 'should expose the app config in a service', (done) ->
|
20 |
|
21 |
|
22 | axiomConfig =
|
23 | app:
|
24 | serverPort: 4000
|
25 | apiPort: 4001
|
26 |
|
27 |
|
28 | runService = (args, fin) ->
|
29 | should.exist @app
|
30 | @app.should.eql axiomConfig.app
|
31 | fin()
|
32 |
|
33 |
|
34 | initCore {
|
35 | axiom: axiomConfig
|
36 | node_modules:
|
37 | 'axiom-server':
|
38 | services:
|
39 | run: runService
|
40 | }
|
41 |
|
42 |
|
43 | core.request 'server.run', {}, (err, result) ->
|
44 |
|
45 |
|
46 | should.not.exist err
|
47 | done()
|
48 |
|
49 | it 'should expose an empty object for the app config', (done) ->
|
50 |
|
51 |
|
52 | axiomConfig = {}
|
53 |
|
54 |
|
55 | runService = (args, fin) ->
|
56 | should.exist @app
|
57 | @app.should.eql {}
|
58 | fin()
|
59 |
|
60 |
|
61 | initCore {
|
62 | axiom: axiomConfig
|
63 | node_modules:
|
64 | 'axiom-server':
|
65 | services:
|
66 | run: runService
|
67 | }
|
68 |
|
69 |
|
70 | core.request 'server.run', {}, (err, result) ->
|
71 |
|
72 |
|
73 | should.not.exist err
|
74 | done()
|
75 |
|
76 | it 'should expose app config to a base script', (done) ->
|
77 |
|
78 |
|
79 | axiomConfig =
|
80 | app:
|
81 | serverPort: 4000
|
82 | apiPort: 4001
|
83 |
|
84 |
|
85 | baseService = (args, next) ->
|
86 | should.exist @app
|
87 | @app.should.eql axiomConfig.app
|
88 | next()
|
89 |
|
90 |
|
91 | initCore {
|
92 | axiom: axiomConfig
|
93 | node_modules:
|
94 | 'axiom-server':
|
95 | config:
|
96 | run:
|
97 | base: 'runtime'
|
98 | 'axiom-base':
|
99 | {
|
100 | services:
|
101 | runtime: baseService
|
102 | }
|
103 | }
|
104 |
|
105 |
|
106 | core.request 'server.run', {}, (err, result) ->
|
107 |
|
108 |
|
109 | should.not.exist err
|
110 | done()
|
111 |
|
112 | it 'should expose app config to module configs', (done) ->
|
113 |
|
114 |
|
115 | axiomConfig =
|
116 | app:
|
117 | serverPort: 4000
|
118 | apiPort: 4001
|
119 |
|
120 |
|
121 | moduleConfig = (app) ->
|
122 |
|
123 |
|
124 | should.exist app
|
125 | app.should.eql axiomConfig.app
|
126 | done()
|
127 | return app
|
128 |
|
129 |
|
130 | initCore {
|
131 | axiom: axiomConfig
|
132 | axiom_configs:
|
133 | server: moduleConfig
|
134 | }
|
135 |
|
136 | it 'should load an object based module config', (done) ->
|
137 |
|
138 |
|
139 | moduleConfig = {run: {foo: 'yes'}}
|
140 |
|
141 |
|
142 | runService = (args, fin) ->
|
143 | should.exist @config
|
144 | @config.should.eql moduleConfig.run
|
145 | fin()
|
146 |
|
147 |
|
148 | initCore {
|
149 | axiom_configs:
|
150 | server: moduleConfig
|
151 | node_modules:
|
152 | 'axiom-server':
|
153 | services:
|
154 | run: runService
|
155 | }
|
156 |
|
157 |
|
158 | core.request 'server.run', {}, (err, result) ->
|
159 |
|
160 |
|
161 | should.not.exist err
|
162 | done()
|