diff --git a/CHANGELOG.md b/CHANGELOG.md index 437f403d587..007f97677b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Introduce `AppSettings` instead of `Parameters` (#3163) - Remove unused testutil.TempSocketName (#3291) - Move BigEndian helper functions in `tracetranslator` to an internal package.(#3298) +- Rename `configtest.LoadConfigFile` to `configtest.LoadConfigAndValidate` (#3306) ## 💡 Enhancements 💡 diff --git a/config/configtest/configtest.go b/config/configtest/configtest.go index 84014da91f4..21a26528c69 100644 --- a/config/configtest/configtest.go +++ b/config/configtest/configtest.go @@ -15,23 +15,26 @@ package configtest import ( - "testing" - - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configloader" "go.opentelemetry.io/collector/config/configparser" ) -// LoadConfigFile loads a config from file. -func LoadConfigFile(t *testing.T, fileName string, factories component.Factories) (*config.Config, error) { - // Read yaml config from file. +// LoadConfig loads a config from file, and does NOT validate the configuration. +func LoadConfig(fileName string, factories component.Factories) (*config.Config, error) { + // Read yaml config from file cp, err := configparser.NewParserFromFile(fileName) - require.NoError(t, err) - // Load the config from viper using the given factories. - cfg, err := configloader.Load(cp, factories) + if err != nil { + return nil, err + } + // Load the config using the given factories. + return configloader.Load(cp, factories) +} + +// LoadConfigAndValidate loads a config from the file, and validates the configuration. +func LoadConfigAndValidate(fileName string, factories component.Factories) (*config.Config, error) { + cfg, err := LoadConfig(fileName, factories) if err != nil { return nil, err } diff --git a/config/configtest/configtest_test.go b/config/configtest/configtest_test.go index 9648f7b7d09..4fc9c443ab1 100644 --- a/config/configtest/configtest_test.go +++ b/config/configtest/configtest_test.go @@ -24,12 +24,12 @@ import ( "go.opentelemetry.io/collector/config" ) -func TestLoadConfigFile(t *testing.T) { +func TestLoadConfig(t *testing.T) { factories, err := componenttest.NopFactories() assert.NoError(t, err) - cfg, err := LoadConfigFile(t, "testdata/config.yaml", factories) - require.NoError(t, err, "Unable to load config") + cfg, err := LoadConfig("testdata/config.yaml", factories) + require.NoError(t, err) // Verify extensions. require.Len(t, cfg.Extensions, 2) @@ -66,3 +66,16 @@ func TestLoadConfigFile(t *testing.T) { cfg.Service.Pipelines["traces"], "Did not load pipeline config correctly") } + +func TestLoadConfigAndValidate(t *testing.T) { + factories, err := componenttest.NopFactories() + assert.NoError(t, err) + + cfgValidate, errValidate := LoadConfigAndValidate("testdata/config.yaml", factories) + require.NoError(t, errValidate) + + cfg, errLoad := LoadConfig("testdata/config.yaml", factories) + require.NoError(t, errLoad) + + assert.Equal(t, cfg, cfgValidate) +} diff --git a/exporter/fileexporter/config_test.go b/exporter/fileexporter/config_test.go index 863d4475564..07b372aac09 100644 --- a/exporter/fileexporter/config_test.go +++ b/exporter/fileexporter/config_test.go @@ -32,7 +32,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.EqualError(t, err, "exporter \"file\" has invalid configuration: path must be non-empty") require.NotNil(t, cfg) diff --git a/exporter/jaegerexporter/config_test.go b/exporter/jaegerexporter/config_test.go index 3e501f413bb..3b020d67b4f 100644 --- a/exporter/jaegerexporter/config_test.go +++ b/exporter/jaegerexporter/config_test.go @@ -38,7 +38,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/exporter/kafkaexporter/config_test.go b/exporter/kafkaexporter/config_test.go index b2f9e45e0ac..fee93e9f09e 100644 --- a/exporter/kafkaexporter/config_test.go +++ b/exporter/kafkaexporter/config_test.go @@ -34,7 +34,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.Equal(t, 1, len(cfg.Exporters)) diff --git a/exporter/loggingexporter/config_test.go b/exporter/loggingexporter/config_test.go index fb46b6e6dcb..a76d01587d8 100644 --- a/exporter/loggingexporter/config_test.go +++ b/exporter/loggingexporter/config_test.go @@ -32,7 +32,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/exporter/opencensusexporter/config_test.go b/exporter/opencensusexporter/config_test.go index f7f0add5813..529537d0029 100644 --- a/exporter/opencensusexporter/config_test.go +++ b/exporter/opencensusexporter/config_test.go @@ -36,7 +36,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index a87681027ac..db4d56877c8 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -37,7 +37,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/exporter/otlphttpexporter/config_test.go b/exporter/otlphttpexporter/config_test.go index 1fd6670f656..31a6eecef67 100644 --- a/exporter/otlphttpexporter/config_test.go +++ b/exporter/otlphttpexporter/config_test.go @@ -36,7 +36,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/exporter/prometheusexporter/config_test.go b/exporter/prometheusexporter/config_test.go index ade4a2e8010..13de50f5284 100644 --- a/exporter/prometheusexporter/config_test.go +++ b/exporter/prometheusexporter/config_test.go @@ -33,7 +33,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/exporter/prometheusremotewriteexporter/config_test.go b/exporter/prometheusremotewriteexporter/config_test.go index d5b4cc93d68..253d51eb1ec 100644 --- a/exporter/prometheusremotewriteexporter/config_test.go +++ b/exporter/prometheusremotewriteexporter/config_test.go @@ -37,7 +37,7 @@ func Test_loadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -89,7 +89,7 @@ func TestNegativeQueueSize(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "negative_queue_size.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "negative_queue_size.yaml"), factories) assert.Error(t, err) } @@ -99,6 +99,6 @@ func TestNegativeNumConsumers(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "negative_num_consumers.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "negative_num_consumers.yaml"), factories) assert.Error(t, err) } diff --git a/exporter/zipkinexporter/config_test.go b/exporter/zipkinexporter/config_test.go index f4570108390..6a035f5e6bf 100644 --- a/exporter/zipkinexporter/config_test.go +++ b/exporter/zipkinexporter/config_test.go @@ -38,7 +38,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/extension/ballastextension/config_test.go b/extension/ballastextension/config_test.go index 39d0132fc7a..5b76e7338df 100644 --- a/extension/ballastextension/config_test.go +++ b/extension/ballastextension/config_test.go @@ -32,7 +32,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Extensions[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.Nil(t, err) require.NotNil(t, cfg) diff --git a/extension/healthcheckextension/config_test.go b/extension/healthcheckextension/config_test.go index c154e2cc661..c24c2c867b4 100644 --- a/extension/healthcheckextension/config_test.go +++ b/extension/healthcheckextension/config_test.go @@ -33,7 +33,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Extensions[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.Nil(t, err) require.NotNil(t, cfg) diff --git a/extension/pprofextension/config_test.go b/extension/pprofextension/config_test.go index 558c8b2fa8d..7cce52a503d 100644 --- a/extension/pprofextension/config_test.go +++ b/extension/pprofextension/config_test.go @@ -33,7 +33,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Extensions[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.Nil(t, err) require.NotNil(t, cfg) diff --git a/extension/zpagesextension/config_test.go b/extension/zpagesextension/config_test.go index f984ad64bfa..7fc7ca01f3a 100644 --- a/extension/zpagesextension/config_test.go +++ b/extension/zpagesextension/config_test.go @@ -33,7 +33,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Extensions[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.Nil(t, err) require.NotNil(t, cfg) diff --git a/processor/attributesprocessor/config_test.go b/processor/attributesprocessor/config_test.go index b6f66b70803..61a5a0dfb81 100644 --- a/processor/attributesprocessor/config_test.go +++ b/processor/attributesprocessor/config_test.go @@ -35,7 +35,7 @@ func TestLoadingConfig(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) assert.NoError(t, err) require.NotNil(t, cfg) diff --git a/processor/batchprocessor/config_test.go b/processor/batchprocessor/config_test.go index 469a60fe509..90f32e35193 100644 --- a/processor/batchprocessor/config_test.go +++ b/processor/batchprocessor/config_test.go @@ -33,7 +33,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.Nil(t, err) require.NotNil(t, cfg) diff --git a/processor/filterprocessor/config_test.go b/processor/filterprocessor/config_test.go index 998e90a2021..2a73a83c3bd 100644 --- a/processor/filterprocessor/config_test.go +++ b/processor/filterprocessor/config_test.go @@ -46,7 +46,7 @@ func TestLoadingConfigStrict(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config_strict.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config_strict.yaml"), factories) assert.Nil(t, err) require.NotNil(t, cfg) @@ -128,7 +128,7 @@ func TestLoadingConfigRegexp(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config_regexp.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config_regexp.yaml"), factories) assert.Nil(t, err) require.NotNil(t, cfg) @@ -193,7 +193,7 @@ func TestLoadingConfigExpr(t *testing.T) { require.NoError(t, err) factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config_expr.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config_expr.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/processor/filterprocessor/factory_test.go b/processor/filterprocessor/factory_test.go index 7b93b4cf616..5cf12a6d236 100644 --- a/processor/filterprocessor/factory_test.go +++ b/processor/filterprocessor/factory_test.go @@ -70,7 +70,7 @@ func TestCreateProcessors(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", test.configName), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", test.configName), factories) assert.Nil(t, err) for name, cfg := range cfg.Processors { diff --git a/processor/memorylimiter/config_test.go b/processor/memorylimiter/config_test.go index 451a5ce7d4e..f2cbcb0e0c0 100644 --- a/processor/memorylimiter/config_test.go +++ b/processor/memorylimiter/config_test.go @@ -34,10 +34,7 @@ func TestLoadConfig(t *testing.T) { factories.Processors[typeStr] = factory require.NoError(t, err) - cfg, err := configtest.LoadConfigFile( - t, - path.Join(".", "testdata", "config.yaml"), - factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.Nil(t, err) require.NotNil(t, cfg) diff --git a/processor/probabilisticsamplerprocessor/config_test.go b/processor/probabilisticsamplerprocessor/config_test.go index 964efbc76ff..d363c904249 100644 --- a/processor/probabilisticsamplerprocessor/config_test.go +++ b/processor/probabilisticsamplerprocessor/config_test.go @@ -32,7 +32,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -53,7 +53,7 @@ func TestLoadConfigEmpty(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "empty.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "empty.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/processor/resourceprocessor/config_test.go b/processor/resourceprocessor/config_test.go index b17cfc00180..ebcb7a03d1b 100644 --- a/processor/resourceprocessor/config_test.go +++ b/processor/resourceprocessor/config_test.go @@ -32,7 +32,7 @@ func TestLoadConfig(t *testing.T) { factories.Processors[typeStr] = NewFactory() - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) assert.NoError(t, err) assert.NotNil(t, cfg) diff --git a/processor/spanprocessor/config_test.go b/processor/spanprocessor/config_test.go index 399220a81fa..d5905fdb35a 100644 --- a/processor/spanprocessor/config_test.go +++ b/processor/spanprocessor/config_test.go @@ -34,7 +34,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Processors[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) assert.NoError(t, err) assert.NotNil(t, cfg) diff --git a/receiver/hostmetricsreceiver/config_test.go b/receiver/hostmetricsreceiver/config_test.go index 32af833e7e4..232593295d6 100644 --- a/receiver/hostmetricsreceiver/config_test.go +++ b/receiver/hostmetricsreceiver/config_test.go @@ -45,7 +45,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -98,7 +98,7 @@ func TestLoadInvalidConfig_NoScrapers(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "config-noscrapers.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config-noscrapers.yaml"), factories) require.EqualError(t, err, "receiver \"hostmetrics\" has invalid configuration: must specify at least one scraper when using hostmetrics receiver") } @@ -109,7 +109,7 @@ func TestLoadInvalidConfig_InvalidScraperKey(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "config-invalidscraperkey.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config-invalidscraperkey.yaml"), factories) require.EqualError(t, err, "error reading receivers configuration for hostmetrics: invalid scraper key: invalidscraperkey") } diff --git a/receiver/jaegerreceiver/config_test.go b/receiver/jaegerreceiver/config_test.go index f28262347e5..aac167eea1a 100644 --- a/receiver/jaegerreceiver/config_test.go +++ b/receiver/jaegerreceiver/config_test.go @@ -36,7 +36,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -159,15 +159,15 @@ func TestFailedLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "bad_typo_default_proto_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "bad_typo_default_proto_config.yaml"), factories) assert.EqualError(t, err, "error reading receivers configuration for jaeger: unknown protocols in the Jaeger receiver") - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "bad_proto_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "bad_proto_config.yaml"), factories) assert.EqualError(t, err, "error reading receivers configuration for jaeger: 1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift_htttp") - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "bad_no_proto_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "bad_no_proto_config.yaml"), factories) assert.EqualError(t, err, "receiver \"jaeger\" has invalid configuration: must specify at least one protocol when using the Jaeger receiver") - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "bad_empty_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "bad_empty_config.yaml"), factories) assert.EqualError(t, err, "error reading receivers configuration for jaeger: empty config for Jaeger receiver") } diff --git a/receiver/jaegerreceiver/factory_test.go b/receiver/jaegerreceiver/factory_test.go index 2102396a977..2a4bcf3664b 100644 --- a/receiver/jaegerreceiver/factory_test.go +++ b/receiver/jaegerreceiver/factory_test.go @@ -76,7 +76,7 @@ func TestCreateReceiverGeneralConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/receiver/kafkareceiver/config_test.go b/receiver/kafkareceiver/config_test.go index 436e533d329..3bf6eacf3e6 100644 --- a/receiver/kafkareceiver/config_test.go +++ b/receiver/kafkareceiver/config_test.go @@ -35,7 +35,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.Equal(t, 1, len(cfg.Receivers)) diff --git a/receiver/opencensusreceiver/config_test.go b/receiver/opencensusreceiver/config_test.go index ad719c1d065..b0562b64307 100644 --- a/receiver/opencensusreceiver/config_test.go +++ b/receiver/opencensusreceiver/config_test.go @@ -36,7 +36,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/receiver/otlpreceiver/config_test.go b/receiver/otlpreceiver/config_test.go index 410ae09c113..425cc93dff6 100644 --- a/receiver/otlpreceiver/config_test.go +++ b/receiver/otlpreceiver/config_test.go @@ -37,7 +37,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -198,15 +198,15 @@ func TestFailedLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "typo_default_proto_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "typo_default_proto_config.yaml"), factories) assert.EqualError(t, err, `error reading receivers configuration for otlp: unknown protocols in the OTLP receiver`) - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "bad_proto_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "bad_proto_config.yaml"), factories) assert.EqualError(t, err, "error reading receivers configuration for otlp: 1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift") - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "bad_no_proto_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "bad_no_proto_config.yaml"), factories) assert.EqualError(t, err, "receiver \"otlp\" has invalid configuration: must specify at least one protocol when using the OTLP receiver") - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "bad_empty_config.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "bad_empty_config.yaml"), factories) assert.EqualError(t, err, "error reading receivers configuration for otlp: empty config for OTLP receiver") } diff --git a/receiver/prometheusreceiver/config_test.go b/receiver/prometheusreceiver/config_test.go index dd3fd16c374..0e46de7ea5d 100644 --- a/receiver/prometheusreceiver/config_test.go +++ b/receiver/prometheusreceiver/config_test.go @@ -36,7 +36,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -63,7 +63,7 @@ func TestLoadConfigWithEnvVar(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config_env.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config_env.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -84,7 +84,7 @@ func TestLoadConfigK8s(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config_k8s.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config_k8s.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) @@ -107,12 +107,9 @@ func TestLoadConfigFailsOnUnknownSection(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile( - t, - path.Join(".", "testdata", "invalid-config-section.yaml"), factories) - - require.Error(t, err) - require.Nil(t, cfg) + cfg, err := configtest.LoadConfig(path.Join(".", "testdata", "invalid-config-section.yaml"), factories) + assert.Error(t, err) + assert.Nil(t, cfg) } // As one of the config parameters is consuming prometheus @@ -124,10 +121,7 @@ func TestLoadConfigFailsOnUnknownPrometheusSection(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile( - t, - path.Join(".", "testdata", "invalid-config-prometheus-section.yaml"), factories) - - require.Error(t, err) - require.Nil(t, cfg) + cfg, err := configtest.LoadConfig(path.Join(".", "testdata", "invalid-config-prometheus-section.yaml"), factories) + assert.Error(t, err) + assert.Nil(t, cfg) } diff --git a/receiver/prometheusreceiver/factory_test.go b/receiver/prometheusreceiver/factory_test.go index a167afeb004..6f365445bac 100644 --- a/receiver/prometheusreceiver/factory_test.go +++ b/receiver/prometheusreceiver/factory_test.go @@ -50,7 +50,7 @@ func TestFactoryCanParseServiceDiscoveryConfigs(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - _, err = configtest.LoadConfigFile(t, path.Join(".", "testdata", "config_sd.yaml"), factories) + _, err = configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config_sd.yaml"), factories) assert.NoError(t, err) } diff --git a/receiver/zipkinreceiver/config_test.go b/receiver/zipkinreceiver/config_test.go index 86a11ac7775..9c33ae56475 100644 --- a/receiver/zipkinreceiver/config_test.go +++ b/receiver/zipkinreceiver/config_test.go @@ -33,7 +33,7 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() factories.Receivers[typeStr] = factory - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/service/internal/builder/exporters_builder_test.go b/service/internal/builder/exporters_builder_test.go index 03a4e0641a4..8f254dd56ad 100644 --- a/service/internal/builder/exporters_builder_test.go +++ b/service/internal/builder/exporters_builder_test.go @@ -235,7 +235,7 @@ func TestBuildExporters_NotSupportedDataType(t *testing.T) { for _, test := range tests { t.Run(test.configFile, func(t *testing.T) { - cfg, err := configtest.LoadConfigFile(t, path.Join("testdata", test.configFile), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join("testdata", test.configFile), factories) require.Nil(t, err) exporters, err := BuildExporters(zap.NewNop(), component.DefaultBuildInfo(), cfg, factories.Exporters) diff --git a/service/internal/builder/pipelines_builder_test.go b/service/internal/builder/pipelines_builder_test.go index c2f3fc680ea..d5690fa13d3 100644 --- a/service/internal/builder/pipelines_builder_test.go +++ b/service/internal/builder/pipelines_builder_test.go @@ -180,7 +180,7 @@ func TestBuildPipelines_BuildVarious(t *testing.T) { func testPipeline(t *testing.T, pipelineName string, exporterIDs []config.ComponentID) { factories, err := testcomponents.ExampleComponents() assert.NoError(t, err) - cfg, err := configtest.LoadConfigFile(t, "testdata/pipelines_builder.yaml", factories) + cfg, err := configtest.LoadConfigAndValidate("testdata/pipelines_builder.yaml", factories) // Load the config require.Nil(t, err) @@ -256,7 +256,7 @@ func TestBuildPipelines_NotSupportedDataType(t *testing.T) { for _, test := range tests { t.Run(test.configFile, func(t *testing.T) { - cfg, err := configtest.LoadConfigFile(t, path.Join("testdata", test.configFile), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join("testdata", test.configFile), factories) require.Nil(t, err) allExporters, err := BuildExporters(zap.NewNop(), component.DefaultBuildInfo(), cfg, factories.Exporters) diff --git a/service/internal/builder/receivers_builder_test.go b/service/internal/builder/receivers_builder_test.go index b30217b649e..28169e0bb9b 100644 --- a/service/internal/builder/receivers_builder_test.go +++ b/service/internal/builder/receivers_builder_test.go @@ -96,7 +96,7 @@ func testReceivers( attrFactory := attributesprocessor.NewFactory() factories.Processors[attrFactory.Type()] = attrFactory - cfg, err := configtest.LoadConfigFile(t, "testdata/pipelines_builder.yaml", factories) + cfg, err := configtest.LoadConfigAndValidate("testdata/pipelines_builder.yaml", factories) require.NoError(t, err) // Build the pipeline @@ -298,7 +298,7 @@ func TestBuildReceivers_Unused(t *testing.T) { factories, err := testcomponents.ExampleComponents() assert.NoError(t, err) - cfg, err := configtest.LoadConfigFile(t, "testdata/unused_receiver.yaml", factories) + cfg, err := configtest.LoadConfigAndValidate("testdata/unused_receiver.yaml", factories) assert.NoError(t, err) // Build the pipeline @@ -334,7 +334,7 @@ func TestBuildReceivers_NotSupportedDataType(t *testing.T) { for _, test := range tests { t.Run(test.configFile, func(t *testing.T) { - cfg, err := configtest.LoadConfigFile(t, path.Join("testdata", test.configFile), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join("testdata", test.configFile), factories) assert.NoError(t, err) require.NotNil(t, cfg) diff --git a/service/service_test.go b/service/service_test.go index 44a452007e9..415105cbde8 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -101,7 +101,7 @@ func createExampleService(t *testing.T) *service { // Create some factories. factories, err := componenttest.NopFactories() require.NoError(t, err) - cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "otelcol-nop.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "otelcol-nop.yaml"), factories) require.NoError(t, err) srv, err := newService(&svcSettings{