@@ -18,7 +18,6 @@ import (
18
18
19
19
"go.opentelemetry.io/collector/component"
20
20
"go.opentelemetry.io/collector/confmap"
21
- "go.opentelemetry.io/collector/confmap/converter/expandconverter"
22
21
"go.opentelemetry.io/collector/extension/extensiontest"
23
22
"go.opentelemetry.io/collector/processor/processortest"
24
23
)
@@ -32,13 +31,10 @@ func TestStateString(t *testing.T) {
32
31
}
33
32
34
33
func TestCollectorStartAsGoRoutine (t * testing.T ) {
35
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-nop.yaml" )}))
36
- require .NoError (t , err )
37
-
38
34
set := CollectorSettings {
39
- BuildInfo : component .NewDefaultBuildInfo (),
40
- Factories : nopFactories ,
41
- ConfigProvider : cfgProvider ,
35
+ BuildInfo : component .NewDefaultBuildInfo (),
36
+ Factories : nopFactories ,
37
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-nop.yaml" )}) ,
42
38
}
43
39
col , err := NewCollector (set )
44
40
require .NoError (t , err )
@@ -56,13 +52,10 @@ func TestCollectorStartAsGoRoutine(t *testing.T) {
56
52
}
57
53
58
54
func TestCollectorCancelContext (t * testing.T ) {
59
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-nop.yaml" )}))
60
- require .NoError (t , err )
61
-
62
55
set := CollectorSettings {
63
- BuildInfo : component .NewDefaultBuildInfo (),
64
- Factories : nopFactories ,
65
- ConfigProvider : cfgProvider ,
56
+ BuildInfo : component .NewDefaultBuildInfo (),
57
+ Factories : nopFactories ,
58
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-nop.yaml" )}) ,
66
59
}
67
60
col , err := NewCollector (set )
68
61
require .NoError (t , err )
@@ -119,13 +112,10 @@ func TestCollectorStateAfterConfigChange(t *testing.T) {
119
112
}
120
113
121
114
func TestCollectorReportError (t * testing.T ) {
122
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-nop.yaml" )}))
123
- require .NoError (t , err )
124
-
125
115
col , err := NewCollector (CollectorSettings {
126
- BuildInfo : component .NewDefaultBuildInfo (),
127
- Factories : nopFactories ,
128
- ConfigProvider : cfgProvider ,
116
+ BuildInfo : component .NewDefaultBuildInfo (),
117
+ Factories : nopFactories ,
118
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-nop.yaml" )}) ,
129
119
})
130
120
require .NoError (t , err )
131
121
@@ -235,13 +225,10 @@ func TestComponentStatusWatcher(t *testing.T) {
235
225
}
236
226
237
227
func TestCollectorSendSignal (t * testing.T ) {
238
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-nop.yaml" )}))
239
- require .NoError (t , err )
240
-
241
228
col , err := NewCollector (CollectorSettings {
242
- BuildInfo : component .NewDefaultBuildInfo (),
243
- Factories : nopFactories ,
244
- ConfigProvider : cfgProvider ,
229
+ BuildInfo : component .NewDefaultBuildInfo (),
230
+ Factories : nopFactories ,
231
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-nop.yaml" )}) ,
245
232
})
246
233
require .NoError (t , err )
247
234
@@ -266,13 +253,10 @@ func TestCollectorSendSignal(t *testing.T) {
266
253
func TestCollectorFailedShutdown (t * testing.T ) {
267
254
t .Skip ("This test was using telemetry shutdown failure, switch to use a component that errors on shutdown." )
268
255
269
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-nop.yaml" )}))
270
- require .NoError (t , err )
271
-
272
256
col , err := NewCollector (CollectorSettings {
273
- BuildInfo : component .NewDefaultBuildInfo (),
274
- Factories : nopFactories ,
275
- ConfigProvider : cfgProvider ,
257
+ BuildInfo : component .NewDefaultBuildInfo (),
258
+ Factories : nopFactories ,
259
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-nop.yaml" )}) ,
276
260
})
277
261
require .NoError (t , err )
278
262
@@ -294,16 +278,49 @@ func TestCollectorFailedShutdown(t *testing.T) {
294
278
}
295
279
296
280
func TestCollectorStartInvalidConfig (t * testing.T ) {
297
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-invalid.yaml" )}))
281
+ col , err := NewCollector (CollectorSettings {
282
+ BuildInfo : component .NewDefaultBuildInfo (),
283
+ Factories : nopFactories ,
284
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-invalid.yaml" )}),
285
+ })
298
286
require .NoError (t , err )
287
+ assert .Error (t , col .Run (context .Background ()))
288
+ }
289
+
290
+ func TestNewCollectorInvalidConfigProviderSettings (t * testing.T ) {
291
+ _ , err := NewCollector (CollectorSettings {
292
+ BuildInfo : component .NewDefaultBuildInfo (),
293
+ Factories : nopFactories ,
294
+ ConfigProviderSettings : ConfigProviderSettings {},
295
+ })
296
+ require .Error (t , err )
297
+ }
298
+
299
+ func TestNewCollectorUseConfig (t * testing.T ) {
300
+ set := newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-nop.yaml" )})
299
301
300
302
col , err := NewCollector (CollectorSettings {
301
- BuildInfo : component .NewDefaultBuildInfo (),
302
- Factories : nopFactories ,
303
- ConfigProvider : cfgProvider ,
303
+ BuildInfo : component .NewDefaultBuildInfo (),
304
+ Factories : nopFactories ,
305
+ ConfigProviderSettings : set ,
304
306
})
305
307
require .NoError (t , err )
306
- assert .Error (t , col .Run (context .Background ()))
308
+ require .NotNil (t , col .configProvider )
309
+ }
310
+
311
+ func TestNewCollectorValidatesResolverSettings (t * testing.T ) {
312
+ set := ConfigProviderSettings {
313
+ ResolverSettings : confmap.ResolverSettings {
314
+ URIs : []string {filepath .Join ("testdata" , "otelcol-nop.yaml" )},
315
+ },
316
+ }
317
+
318
+ _ , err := NewCollector (CollectorSettings {
319
+ BuildInfo : component .NewDefaultBuildInfo (),
320
+ Factories : nopFactories ,
321
+ ConfigProviderSettings : set ,
322
+ })
323
+ require .Error (t , err )
307
324
}
308
325
309
326
func TestCollectorStartWithTraceContextPropagation (t * testing.T ) {
@@ -318,13 +335,10 @@ func TestCollectorStartWithTraceContextPropagation(t *testing.T) {
318
335
319
336
for _ , tt := range tests {
320
337
t .Run (tt .file , func (t * testing.T ) {
321
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , tt .file )}))
322
- require .NoError (t , err )
323
-
324
338
set := CollectorSettings {
325
- BuildInfo : component .NewDefaultBuildInfo (),
326
- Factories : nopFactories ,
327
- ConfigProvider : cfgProvider ,
339
+ BuildInfo : component .NewDefaultBuildInfo (),
340
+ Factories : nopFactories ,
341
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , tt . file )}) ,
328
342
}
329
343
330
344
col , err := NewCollector (set )
@@ -353,13 +367,10 @@ func TestCollectorRun(t *testing.T) {
353
367
354
368
for _ , tt := range tests {
355
369
t .Run (tt .file , func (t * testing.T ) {
356
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , tt .file )}))
357
- require .NoError (t , err )
358
-
359
370
set := CollectorSettings {
360
- BuildInfo : component .NewDefaultBuildInfo (),
361
- Factories : nopFactories ,
362
- ConfigProvider : cfgProvider ,
371
+ BuildInfo : component .NewDefaultBuildInfo (),
372
+ Factories : nopFactories ,
373
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , tt . file )}) ,
363
374
}
364
375
col , err := NewCollector (set )
365
376
require .NoError (t , err )
@@ -374,13 +385,10 @@ func TestCollectorRun(t *testing.T) {
374
385
}
375
386
376
387
func TestCollectorShutdownBeforeRun (t * testing.T ) {
377
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-nop.yaml" )}))
378
- require .NoError (t , err )
379
-
380
388
set := CollectorSettings {
381
- BuildInfo : component .NewDefaultBuildInfo (),
382
- Factories : nopFactories ,
383
- ConfigProvider : cfgProvider ,
389
+ BuildInfo : component .NewDefaultBuildInfo (),
390
+ Factories : nopFactories ,
391
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-nop.yaml" )}) ,
384
392
}
385
393
col , err := NewCollector (set )
386
394
require .NoError (t , err )
@@ -396,14 +404,11 @@ func TestCollectorShutdownBeforeRun(t *testing.T) {
396
404
}
397
405
398
406
func TestCollectorClosedStateOnStartUpError (t * testing.T ) {
399
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-invalid.yaml" )}))
400
- require .NoError (t , err )
401
-
402
407
// Load a bad config causing startup to fail
403
408
set := CollectorSettings {
404
- BuildInfo : component .NewDefaultBuildInfo (),
405
- Factories : nopFactories ,
406
- ConfigProvider : cfgProvider ,
409
+ BuildInfo : component .NewDefaultBuildInfo (),
410
+ Factories : nopFactories ,
411
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-invalid.yaml" )}) ,
407
412
}
408
413
col , err := NewCollector (set )
409
414
require .NoError (t , err )
@@ -416,14 +421,11 @@ func TestCollectorClosedStateOnStartUpError(t *testing.T) {
416
421
}
417
422
418
423
func TestCollectorDryRun (t * testing.T ) {
419
- cfgProvider , err := NewConfigProvider (newDefaultConfigProviderSettings ([]string {filepath .Join ("testdata" , "otelcol-invalid.yaml" )}))
420
- require .NoError (t , err )
421
-
422
424
// Load a bad config causing startup to fail
423
425
set := CollectorSettings {
424
- BuildInfo : component .NewDefaultBuildInfo (),
425
- Factories : nopFactories ,
426
- ConfigProvider : cfgProvider ,
426
+ BuildInfo : component .NewDefaultBuildInfo (),
427
+ Factories : nopFactories ,
428
+ ConfigProviderSettings : newDefaultConfigProviderSettings ([] string { filepath . Join ( "testdata" , "otelcol-invalid.yaml" )}) ,
427
429
}
428
430
col , err := NewCollector (set )
429
431
require .NoError (t , err )
@@ -432,19 +434,15 @@ func TestCollectorDryRun(t *testing.T) {
432
434
}
433
435
434
436
func TestPassConfmapToServiceFailure (t * testing.T ) {
435
- cfgProvider , err := NewConfigProvider (ConfigProviderSettings {
436
- ResolverSettings : confmap.ResolverSettings {
437
- URIs : []string {filepath .Join ("testdata" , "otelcol-invalid.yaml" )},
438
- Providers : makeMapProvidersMap (newFailureProvider ()),
439
- Converters : []confmap.Converter {expandconverter .New (confmap.ConverterSettings {})},
440
- },
441
- })
442
- require .NoError (t , err )
443
-
444
437
set := CollectorSettings {
445
- BuildInfo : component .NewDefaultBuildInfo (),
446
- Factories : nopFactories ,
447
- ConfigProvider : cfgProvider ,
438
+ BuildInfo : component .NewDefaultBuildInfo (),
439
+ Factories : nopFactories ,
440
+ ConfigProviderSettings : ConfigProviderSettings {
441
+ ResolverSettings : confmap.ResolverSettings {
442
+ URIs : []string {filepath .Join ("testdata" , "otelcol-invalid.yaml" )},
443
+ Providers : makeMapProvidersMap (newFailureProvider ()),
444
+ },
445
+ },
448
446
}
449
447
col , err := NewCollector (set )
450
448
require .NoError (t , err )
0 commit comments