@@ -11,16 +11,6 @@ describe('Config Reader module', function () {
1111 expect ( configReader ) . to . exist
1212 } )
1313
14- it ( 'does not override reporter if it is given' , function ( ) {
15- var config = { serviceName : 'test' , reporter : 'dummy' , apiKey : 'api-key' }
16-
17- var configReader = ConfigReader . create ( config )
18-
19- configReader . getConfig ( )
20-
21- expect ( config . reporter ) . to . eql ( 'dummy' )
22- } )
23-
2414 it ( 'default config should be checked' , function ( ) {
2515 var configReader = ConfigReader . create ( {
2616 serviceName : 'test' ,
@@ -75,18 +65,34 @@ describe('Config Reader module', function () {
7565 expect ( config . test ) . to . eql ( 'env' )
7666 } )
7767
78- it ( 'file config should override default config ' , function ( ) {
68+ it ( 'system configuration should be checked ' , function ( ) {
7969 var configReader = ConfigReader . create ( {
8070 serviceName : 'test' ,
8171 reporter : 'dummy' ,
8272 collectorApiUrl : 'http://c.a.b' ,
8373 apiKey : 'api-key'
8474 } )
8575
86- this . sandbox . stub ( configReader , '_getEnvVarConfig ' , function ( ) {
87- return { }
76+ var getSystemConfigStub = this . sandbox . stub ( configReader , '_getSystemConfig ' , function ( ) {
77+ return { test : 'system' }
8878 } )
8979
80+ var config = configReader . getConfig ( )
81+
82+ expect ( getSystemConfigStub ) . to . have . been . calledOnce
83+ expect ( config . test ) . to . eql ( 'system' )
84+ } )
85+
86+ it ( 'file config should override default config' , function ( ) {
87+ var configReader = ConfigReader . create ( {
88+ serviceName : 'test' ,
89+ reporter : 'dummy' ,
90+ collectorApiUrl : 'http://c.a.b' ,
91+ apiKey : 'api-key'
92+ } )
93+
94+ this . sandbox . stub ( configReader , '_getEnvVarConfig' ) . returns ( { } )
95+
9096 this . sandbox . stub ( configReader , '_getFileConfig' , function ( ) {
9197 return { test : 'file' }
9298 } )
@@ -116,21 +122,37 @@ describe('Config Reader module', function () {
116122 expect ( config . test ) . to . eql ( 'env' )
117123 } )
118124
119- it ( 'parameter config should override environment variable config' , function ( ) {
125+ it ( 'system config should override all env var config' , function ( ) {
126+ var configReader = ConfigReader . create ( { serviceName : 'test' , reporter : 'dummy' , apiKey : 'api-key' } )
127+
128+ this . sandbox . stub ( configReader , '_getSystemConfig' , function ( ) {
129+ return { test : 'system' }
130+ } )
131+
132+ this . sandbox . stub ( configReader , '_getEnvVarConfig' , function ( ) {
133+ return { test : 'env' }
134+ } )
135+
136+ this . sandbox . stub ( configReader , '_getFileConfig' ) . returns ( { } )
137+
138+ var config = configReader . getConfig ( )
139+
140+ expect ( config . test ) . to . eql ( 'system' )
141+ } )
142+
143+ it ( 'parameter config should override system config' , function ( ) {
120144 var configReader = ConfigReader . create ( {
121145 serviceName : 'test' ,
122146 reporter : 'dummy' ,
123147 test : 'param' ,
124148 apiKey : 'api-key'
125149 } )
126150
127- this . sandbox . stub ( configReader , '_getEnvVarConfig ' , function ( ) {
128- return { test : 'env ' }
151+ this . sandbox . stub ( configReader , '_getSystemConfig ' , function ( ) {
152+ return { test : 'system ' }
129153 } )
130154
131- this . sandbox . stub ( configReader , '_getFileConfig' , function ( ) {
132- return { }
133- } )
155+ this . sandbox . stub ( configReader , '_getFileConfig' ) . returns ( { } )
134156
135157 var config = configReader . getConfig ( )
136158
@@ -149,9 +171,7 @@ describe('Config Reader module', function () {
149171 return { configPath : 'default' }
150172 } )
151173
152- var getFileConfigStub = this . sandbox . stub ( configReader , '_getFileConfig' , function ( ) {
153- return { }
154- } )
174+ var getFileConfigStub = this . sandbox . stub ( configReader , '_getFileConfig' ) . returns ( { } )
155175
156176 configReader . getConfig ( )
157177
@@ -170,9 +190,7 @@ describe('Config Reader module', function () {
170190 return { configPath : 'env' }
171191 } )
172192
173- var getFileConfigStub = this . sandbox . stub ( configReader , '_getFileConfig' , function ( ) {
174- return { }
175- } )
193+ var getFileConfigStub = this . sandbox . stub ( configReader , '_getFileConfig' ) . returns ( { } )
176194
177195 configReader . getConfig ( )
178196
@@ -188,9 +206,7 @@ describe('Config Reader module', function () {
188206 apiKey : 'api-key'
189207 } )
190208
191- var getFileConfigStub = this . sandbox . stub ( configReader , '_getFileConfig' , function ( ) {
192- return { }
193- } )
209+ var getFileConfigStub = this . sandbox . stub ( configReader , '_getFileConfig' ) . returns ( { } )
194210
195211 configReader . getConfig ( )
196212
@@ -236,15 +252,16 @@ describe('Config Reader module', function () {
236252 apiKey : 'api-key'
237253 } )
238254 var log = this . sandbox . spy ( console , 'error' )
239- var ignoreHeadersOption = {
255+ var wellformed = {
240256 'user-agent' : [ '007' ]
241257 }
258+
242259 this . sandbox . stub ( configReader , '_readConfigFile' , function ( ) {
243- return { ignoreHeaders : ignoreHeadersOption }
260+ return { ignoreHeaders : wellformed }
244261 } )
245262 try {
246263 var config = configReader . getConfig ( )
247- expect ( config . ignoreHeaders ) . to . eql ( ignoreHeadersOption )
264+ expect ( config . ignoreHeaders ) . to . eql ( wellformed )
248265 expect ( log ) . to . have . been . calledOnce
249266 delete process . env . TRACE_IGNORE_HEADERS
250267 } catch ( err ) {
0 commit comments