diff --git a/receiver/pulsarreceiver/config_test.go b/receiver/pulsarreceiver/config_test.go index b07d0fda6fe1..4baba8033f90 100644 --- a/receiver/pulsarreceiver/config_test.go +++ b/receiver/pulsarreceiver/config_test.go @@ -20,22 +20,19 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yml"), factories) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yml")) require.NoError(t, err) - require.Equal(t, 1, len(cfg.Receivers)) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() - r := cfg.Receivers[config.NewComponentID(typeStr)].(*Config) + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "").String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) assert.Equal(t, &Config{ ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), @@ -46,5 +43,7 @@ func TestLoadConfig(t *testing.T) { Encoding: defaultEncoding, TLSTrustCertsFilePath: "ca.pem", Authentication: Authentication{TLS: &TLS{CertFile: "cert.pem", KeyFile: "key.pem"}}, - }, r) + }, + cfg, + ) } diff --git a/receiver/pulsarreceiver/testdata/config.yml b/receiver/pulsarreceiver/testdata/config.yml index ba3399462143..40de9955e068 100644 --- a/receiver/pulsarreceiver/testdata/config.yml +++ b/receiver/pulsarreceiver/testdata/config.yml @@ -1,25 +1,11 @@ -receivers: - pulsar: - topic: otel-pulsar - endpoint: pulsar://localhost:6500 - consumer_name: otel-collector - subscription: otel-collector - tls_trust_certs_file_path: ca.pem - tls_allow_insecure_connection: false - auth: - tls: - cert_file: cert.pem - key_file: key.pem - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [ pulsar ] - processors: [ nop ] - exporters: [ nop ] \ No newline at end of file +pulsar: + topic: otel-pulsar + endpoint: pulsar://localhost:6500 + consumer_name: otel-collector + subscription: otel-collector + tls_trust_certs_file_path: ca.pem + tls_allow_insecure_connection: false + auth: + tls: + cert_file: cert.pem + key_file: key.pem diff --git a/receiver/rabbitmqreceiver/testdata/config.yaml b/receiver/rabbitmqreceiver/testdata/config.yaml index 5a6bc0bd0fd5..f8e1b0fc6688 100644 --- a/receiver/rabbitmqreceiver/testdata/config.yaml +++ b/receiver/rabbitmqreceiver/testdata/config.yaml @@ -1,19 +1,5 @@ -receivers: - rabbitmq: - endpoint: http://localhost:15672 - username: otelu - password: $RABBITMQ_PASSWORD - collection_interval: 10s - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [rabbitmq] - processors: [nop] - exporters: [nop] +rabbitmq: + endpoint: http://localhost:15672 + username: otelu + password: $RABBITMQ_PASSWORD + collection_interval: 10s diff --git a/receiver/redisreceiver/config_test.go b/receiver/redisreceiver/config_test.go index 01b0b7d73722..618f87b94f3a 100644 --- a/receiver/redisreceiver/config_test.go +++ b/receiver/redisreceiver/config_test.go @@ -21,25 +21,24 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/config/configtls" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/receiver/scraperhelper" - "go.opentelemetry.io/collector/service/servicetest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver/internal/metadata" ) func TestConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) factory := NewFactory() - factories.Receivers[factory.Type()] = factory + cfg := factory.CreateDefaultConfig() - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "").String()) require.NoError(t, err) - require.NotNil(t, cfg) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) assert.Equal(t, &Config{ @@ -57,6 +56,6 @@ func TestConfig(t *testing.T) { }, Metrics: metadata.DefaultMetricsSettings(), }, - cfg.Receivers[config.NewComponentID(typeStr)], + cfg, ) } diff --git a/receiver/redisreceiver/testdata/config.yaml b/receiver/redisreceiver/testdata/config.yaml index 50954b64c18a..018061947a15 100644 --- a/receiver/redisreceiver/testdata/config.yaml +++ b/receiver/redisreceiver/testdata/config.yaml @@ -1,20 +1,6 @@ -receivers: - redis: - endpoint: "localhost:6379" - password: "test" - collection_interval: 10s - tls: - insecure: true - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [redis] - processors: [nop] - exporters: [nop] +redis: + endpoint: "localhost:6379" + password: "test" + collection_interval: 10s + tls: + insecure: true diff --git a/receiver/riakreceiver/testdata/config.yaml b/receiver/riakreceiver/testdata/config.yaml index 731039266316..2ff323a1beba 100644 --- a/receiver/riakreceiver/testdata/config.yaml +++ b/receiver/riakreceiver/testdata/config.yaml @@ -1,19 +1,5 @@ -receivers: - riak: - endpoint: http://localhost:8098 - username: otelu - password: $RIAK_PASSWORD - collection_interval: 10s - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [riak] - processors: [nop] - exporters: [nop] +riak: + endpoint: http://localhost:8098 + username: otelu + password: $RIAK_PASSWORD + collection_interval: 10s diff --git a/receiver/saphanareceiver/testdata/config.yaml b/receiver/saphanareceiver/testdata/config.yaml index 30a4c24c8441..ef3811e95198 100644 --- a/receiver/saphanareceiver/testdata/config.yaml +++ b/receiver/saphanareceiver/testdata/config.yaml @@ -1,22 +1,8 @@ -receivers: - saphana: - metrics: - saphana.cpu.used: - enabled: false - endpoint: example.com:30015 - username: otel - password: password - collection_interval: 2m - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [saphana] - processors: [nop] - exporters: [nop] +saphana: + metrics: + saphana.cpu.used: + enabled: false + endpoint: example.com:30015 + username: otel + password: password + collection_interval: 2m diff --git a/receiver/sapmreceiver/config_test.go b/receiver/sapmreceiver/config_test.go index 4379522098e5..29dfeb0f5b68 100644 --- a/receiver/sapmreceiver/config_test.go +++ b/receiver/sapmreceiver/config_test.go @@ -20,66 +20,77 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - - // The receiver `sapm/disabled` doesn't count because disabled receivers - // are excluded from the final list. - assert.Equal(t, len(cfg.Receivers), 4) - r0 := cfg.Receivers[config.NewComponentID(typeStr)] - assert.Equal(t, r0, factory.CreateDefaultConfig()) - - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "customname")].(*Config) - assert.Equal(t, r1, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "customname")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: "0.0.0.0:7276", + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentIDWithName(typeStr, ""), + expected: createDefaultConfig(), + }, + { + id: config.NewComponentIDWithName(typeStr, "customname"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: "0.0.0.0:7276", + }, }, - }) - - r2 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "tls")].(*Config) - assert.Equal(t, r2, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "tls")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: ":7276", - TLSSetting: &configtls.TLSServerSetting{ - TLSSetting: configtls.TLSSetting{ - CertFile: "/test.crt", - KeyFile: "/test.key", + }, + { + id: config.NewComponentIDWithName(typeStr, "tls"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: ":7276", + TLSSetting: &configtls.TLSServerSetting{ + TLSSetting: configtls.TLSSetting{ + CertFile: "/test.crt", + KeyFile: "/test.key", + }, }, }, }, - }) - - r3 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "passthrough")].(*Config) - assert.Equal(t, r3, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "passthrough")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: ":7276", - }, - AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ - AccessTokenPassthrough: true, + }, + { + id: config.NewComponentIDWithName(typeStr, "passthrough"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: ":7276", + }, + AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ + AccessTokenPassthrough: true, + }, }, + }, + } + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) + } } diff --git a/receiver/sapmreceiver/testdata/config.yaml b/receiver/sapmreceiver/testdata/config.yaml index 48ce70007add..c5fc7de36e79 100644 --- a/receiver/sapmreceiver/testdata/config.yaml +++ b/receiver/sapmreceiver/testdata/config.yaml @@ -1,34 +1,18 @@ -receivers: - # The following demonstrates initializing the default sapm receiver. - # By sapm-http is enabled and the default endpoint is specified in factory.go - sapm: - # The following demonstrates specifying different endpoints. - # The SAPM receiver connects to ports on all available network interfaces. - # Ex: `endpoint: "7276"` is incorrect. - # Ex: `endpoint: "1.2.3.4:7276"` and ":7276" is correct - sapm/customname: - endpoint: "0.0.0.0:7276" +# The following demonstrates initializing the default sapm receiver. +# By sapm-http is enabled and the default endpoint is specified in factory.go +sapm: +# The following demonstrates specifying different endpoints. +# The SAPM receiver connects to ports on all available network interfaces. +# Ex: `endpoint: "7276"` is incorrect. +# Ex: `endpoint: "1.2.3.4:7276"` and ":7276" is correct +sapm/customname: + endpoint: "0.0.0.0:7276" - # The following demonstrates how to specify TLS for the receiver. - sapm/tls: - tls: - cert_file: /test.crt - key_file: /test.key - - sapm/passthrough: - access_token_passthrough: true - - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [sapm] - processors: [nop] - exporters: [nop] +# The following demonstrates how to specify TLS for the receiver. +sapm/tls: + tls: + cert_file: /test.crt + key_file: /test.key +sapm/passthrough: + access_token_passthrough: true diff --git a/receiver/signalfxreceiver/config_test.go b/receiver/signalfxreceiver/config_test.go index 51ff950b6334..8a61a7344651 100644 --- a/receiver/signalfxreceiver/config_test.go +++ b/receiver/signalfxreceiver/config_test.go @@ -20,58 +20,71 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - - assert.Equal(t, len(cfg.Receivers), 3) - r0 := cfg.Receivers[config.NewComponentID(typeStr)] - assert.Equal(t, r0, factory.CreateDefaultConfig()) - - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "allsettings")].(*Config) - assert.Equal(t, r1, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "allsettings")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: "localhost:9943", - }, - AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ - AccessTokenPassthrough: true, + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentIDWithName(typeStr, ""), + expected: createDefaultConfig(), + }, + { + id: config.NewComponentIDWithName(typeStr, "allsettings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: "localhost:9943", + }, + AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ + AccessTokenPassthrough: true, + }, }, - }) - - r2 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "tls")].(*Config) - assert.Equal(t, r2, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "tls")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: ":9943", - TLSSetting: &configtls.TLSServerSetting{ - TLSSetting: configtls.TLSSetting{ - CertFile: "/test.crt", - KeyFile: "/test.key", + }, + { + id: config.NewComponentIDWithName(typeStr, "tls"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: ":9943", + TLSSetting: &configtls.TLSServerSetting{ + TLSSetting: configtls.TLSSetting{ + CertFile: "/test.crt", + KeyFile: "/test.key", + }, }, }, + AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ + AccessTokenPassthrough: false, + }, }, - AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ - AccessTokenPassthrough: false, - }, + }, + } + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) + } } diff --git a/receiver/signalfxreceiver/testdata/config.yaml b/receiver/signalfxreceiver/testdata/config.yaml index ba5748637a7c..64051e14e791 100644 --- a/receiver/signalfxreceiver/testdata/config.yaml +++ b/receiver/signalfxreceiver/testdata/config.yaml @@ -1,24 +1,10 @@ -receivers: - signalfx: - signalfx/allsettings: - # endpoint specifies the network interface and port which will receive - # SignalFx metrics. - endpoint: localhost:9943 - access_token_passthrough: true - signalfx/tls: - tls: - cert_file: /test.crt - key_file: /test.key - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [signalfx, signalfx/allsettings] - processors: [nop] - exporters: [nop] +signalfx: +signalfx/allsettings: + # endpoint specifies the network interface and port which will receive + # SignalFx metrics. + endpoint: localhost:9943 + access_token_passthrough: true +signalfx/tls: + tls: + cert_file: /test.crt + key_file: /test.key diff --git a/receiver/simpleprometheusreceiver/config_test.go b/receiver/simpleprometheusreceiver/config_test.go index e8bbf576aa78..42292f39f5e3 100644 --- a/receiver/simpleprometheusreceiver/config_test.go +++ b/receiver/simpleprometheusreceiver/config_test.go @@ -22,72 +22,85 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - - assert.Equal(t, len(cfg.Receivers), 4) - - r1 := cfg.Receivers[config.NewComponentID(typeStr)] - assert.Equal(t, r1, factory.CreateDefaultConfig()) - r2 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "all_settings")].(*Config) - assert.Equal(t, r2, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "all_settings")), - HTTPClientSettings: confighttp.HTTPClientSettings{ - Endpoint: "localhost:1234", - TLSSetting: configtls.TLSClientSetting{ - TLSSetting: configtls.TLSSetting{ - CAFile: "path", - CertFile: "path", - KeyFile: "path", + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentIDWithName(typeStr, ""), + expected: createDefaultConfig(), + }, + { + id: config.NewComponentIDWithName(typeStr, "all_settings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPClientSettings: confighttp.HTTPClientSettings{ + Endpoint: "localhost:1234", + TLSSetting: configtls.TLSClientSetting{ + TLSSetting: configtls.TLSSetting{ + CAFile: "path", + CertFile: "path", + KeyFile: "path", + }, + InsecureSkipVerify: true, }, - InsecureSkipVerify: true, }, + CollectionInterval: 30 * time.Second, + MetricsPath: "/v2/metrics", + Params: url.Values{"columns": []string{"name", "messages"}, "key": []string{"foo", "bar"}}, + UseServiceAccount: true, }, - CollectionInterval: 30 * time.Second, - MetricsPath: "/v2/metrics", - Params: url.Values{"columns": []string{"name", "messages"}, "key": []string{"foo", "bar"}}, - UseServiceAccount: true, - }) - - r3 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "partial_settings")].(*Config) - assert.Equal(t, r3, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "partial_settings")), - HTTPClientSettings: confighttp.HTTPClientSettings{ - Endpoint: "localhost:1234", - TLSSetting: configtls.TLSClientSetting{ - Insecure: true, + }, + { + id: config.NewComponentIDWithName(typeStr, "partial_settings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPClientSettings: confighttp.HTTPClientSettings{ + Endpoint: "localhost:1234", + TLSSetting: configtls.TLSClientSetting{ + Insecure: true, + }, }, + CollectionInterval: 30 * time.Second, + MetricsPath: "/metrics", }, - CollectionInterval: 30 * time.Second, - MetricsPath: "/metrics", - }) - - r4 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "partial_tls_settings")].(*Config) - assert.Equal(t, r4, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "partial_tls_settings")), - HTTPClientSettings: confighttp.HTTPClientSettings{ - Endpoint: "localhost:1234", + }, + { + id: config.NewComponentIDWithName(typeStr, "partial_tls_settings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPClientSettings: confighttp.HTTPClientSettings{ + Endpoint: "localhost:1234", + }, + CollectionInterval: 30 * time.Second, + MetricsPath: "/metrics", }, - CollectionInterval: 30 * time.Second, - MetricsPath: "/metrics", + }, + } + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) + } } diff --git a/receiver/simpleprometheusreceiver/testdata/config.yaml b/receiver/simpleprometheusreceiver/testdata/config.yaml index a527832a1fc5..63fe57019f2a 100644 --- a/receiver/simpleprometheusreceiver/testdata/config.yaml +++ b/receiver/simpleprometheusreceiver/testdata/config.yaml @@ -1,43 +1,25 @@ -receivers: - prometheus_simple: - prometheus_simple/all_settings: - endpoint: "localhost:1234" - collection_interval: 30s - metrics_path: /v2/metrics - params: - columns: "name,messages" - key: ["foo","bar"] - use_service_account: true - tls: - ca_file: "path" - cert_file: "path" - key_file: "path" - insecure: false - insecure_skip_verify: true - prometheus_simple/partial_settings: - collection_interval: 30s - endpoint: "localhost:1234" - tls: - insecure: true - prometheus_simple/partial_tls_settings: - collection_interval: 30s - endpoint: "localhost:1234" - tls: - insecure: false - - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: - - prometheus_simple - - prometheus_simple/all_settings - - prometheus_simple/partial_settings - processors: [nop] - exporters: [nop] +prometheus_simple: +prometheus_simple/all_settings: + endpoint: "localhost:1234" + collection_interval: 30s + metrics_path: /v2/metrics + params: + columns: "name,messages" + key: [ "foo","bar" ] + use_service_account: true + tls: + ca_file: "path" + cert_file: "path" + key_file: "path" + insecure: false + insecure_skip_verify: true +prometheus_simple/partial_settings: + collection_interval: 30s + endpoint: "localhost:1234" + tls: + insecure: true +prometheus_simple/partial_tls_settings: + collection_interval: 30s + endpoint: "localhost:1234" + tls: + insecure: false diff --git a/receiver/skywalkingreceiver/config_test.go b/receiver/skywalkingreceiver/config_test.go index 9c2e721874d9..d3221105f583 100644 --- a/receiver/skywalkingreceiver/config_test.go +++ b/receiver/skywalkingreceiver/config_test.go @@ -20,49 +20,65 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - - assert.Equal(t, len(cfg.Receivers), 3) - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "customname")].(*Config) - assert.Equal(t, r1, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "customname")), - Protocols: Protocols{ - HTTP: &confighttp.HTTPServerSettings{ - Endpoint: "0.0.0.0:12801", + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentIDWithName(typeStr, ""), + expected: createDefaultConfig(), + }, + { + id: config.NewComponentIDWithName(typeStr, "customname"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + Protocols: Protocols{ + HTTP: &confighttp.HTTPServerSettings{ + Endpoint: "0.0.0.0:12801", + }, }, }, - }) - - rDefaults := cfg.Receivers[config.NewComponentIDWithName(typeStr, "defaults")].(*Config) - assert.Equal(t, rDefaults, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "defaults")), - Protocols: Protocols{ - GRPC: &configgrpc.GRPCServerSettings{ - NetAddr: confignet.NetAddr{ - Endpoint: defaultGRPCBindEndpoint, - Transport: "tcp", + }, + { + id: config.NewComponentIDWithName(typeStr, "defaults"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + Protocols: Protocols{ + GRPC: &configgrpc.GRPCServerSettings{ + NetAddr: confignet.NetAddr{ + Endpoint: defaultGRPCBindEndpoint, + Transport: "tcp", + }, }, }, }, + }, + } + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) + } } diff --git a/receiver/skywalkingreceiver/factory_test.go b/receiver/skywalkingreceiver/factory_test.go index a1ba61694fd1..6a33e8d5ccb7 100644 --- a/receiver/skywalkingreceiver/factory_test.go +++ b/receiver/skywalkingreceiver/factory_test.go @@ -29,7 +29,7 @@ import ( "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/config/configtest" "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" ) func TestTypeStr(t *testing.T) { @@ -66,25 +66,21 @@ func TestCreateReceiver(t *testing.T) { } func TestCreateReceiverGeneralConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) factory := NewFactory() - factories.Receivers[typeStr] = factory + cfg := factory.CreateDefaultConfig() - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "customname").String()) require.NoError(t, err) - require.NotNil(t, cfg) - - rCfg, ok := cfg.Receivers[config.NewComponentIDWithName(typeStr, "customname")] - require.True(t, ok) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) set := componenttest.NewNopReceiverCreateSettings() - tReceiver, err := factory.CreateTracesReceiver(context.Background(), set, rCfg, nil) + tReceiver, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil) assert.NoError(t, err, "receiver creation failed") assert.NotNil(t, tReceiver, "receiver creation failed") - mReceiver, err := factory.CreateMetricsReceiver(context.Background(), set, rCfg, nil) + mReceiver, err := factory.CreateMetricsReceiver(context.Background(), set, cfg, nil) assert.Equal(t, err, component.ErrDataTypeIsNotSupported) assert.Nil(t, mReceiver) } diff --git a/receiver/skywalkingreceiver/testdata/config.yaml b/receiver/skywalkingreceiver/testdata/config.yaml index 398495a929c2..7457f017545b 100644 --- a/receiver/skywalkingreceiver/testdata/config.yaml +++ b/receiver/skywalkingreceiver/testdata/config.yaml @@ -1,28 +1,14 @@ -receivers: - # The following demonstrates how to enable protocols with defaults. - skywalking/defaults: - protocols: - grpc: - skywalking: - protocols: - grpc: - endpoint: 0.0.0.0:11800 - http: - endpoint: 0.0.0.0:12800 - skywalking/customname: - protocols: - http: - endpoint: 0.0.0.0:12801 - -exporters: - nop: - -processors: - nop: - -service: - pipelines: - traces: - receivers: [skywalking] - processors: [nop] - exporters: [nop] +# The following demonstrates how to enable protocols with defaults. +skywalking/defaults: + protocols: + grpc: +skywalking: + protocols: + grpc: + endpoint: 0.0.0.0:11800 + http: + endpoint: 0.0.0.0:12800 +skywalking/customname: + protocols: + http: + endpoint: 0.0.0.0:12801 diff --git a/receiver/solacereceiver/config_test.go b/receiver/solacereceiver/config_test.go index 09a14095100b..861e243a1370 100644 --- a/receiver/solacereceiver/config_test.go +++ b/receiver/solacereceiver/config_test.go @@ -15,11 +15,75 @@ package solacereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/solacereceiver" import ( + "path/filepath" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/config/configtls" + "go.opentelemetry.io/collector/confmap/confmaptest" ) +func TestLoadConfig(t *testing.T) { + t.Parallel() + + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) + + tests := []struct { + id config.ComponentID + expected config.Receiver + expectedErr error + }{ + { + id: config.NewComponentIDWithName(componentType, "primary"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(componentType)), + Broker: []string{"myHost:5671"}, + Auth: Authentication{ + PlainText: &SaslPlainTextConfig{ + Username: "otel", + Password: "otel01$", + }, + }, + Queue: "queue://#trace-profile123", + MaxUnacked: 1234, + TLS: configtls.TLSClientSetting{ + Insecure: false, + InsecureSkipVerify: false, + }, + }, + }, + { + id: config.NewComponentIDWithName(componentType, "noauth"), + expectedErr: errMissingAuthDetails, + }, + { + id: config.NewComponentIDWithName(componentType, "noqueue"), + expectedErr: errMissingQueueName, + }, + } + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + if tt.expectedErr != nil { + assert.ErrorIs(t, cfg.Validate(), tt.expectedErr) + return + } + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) + } +} + func TestConfigValidateMissingAuth(t *testing.T) { cfg := createDefaultConfig().(*Config) cfg.Queue = "someQueue" diff --git a/receiver/solacereceiver/factory_test.go b/receiver/solacereceiver/factory_test.go index ad134ffd68c9..7fd3f7e9cafc 100644 --- a/receiver/solacereceiver/factory_test.go +++ b/receiver/solacereceiver/factory_test.go @@ -16,82 +16,38 @@ package solacereceiver // import "github.com/open-telemetry/opentelemetry-collec import ( "context" - "errors" "path/filepath" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/config/configtls" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/service/servicetest" ) -func TestLoadConfig(t *testing.T) { - factories := getTestNopFactories(t) - - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - - assert.NoError(t, err) - assert.NotNil(t, cfg) - assert.Equal(t, len(cfg.Receivers), 2) - - // validate primary config - primary := cfg.Receivers[config.NewComponentIDWithName(componentType, "primary")].(*Config) - assert.NotNil(t, primary) - assert.Equal(t, "myHost:5671", primary.Broker[0]) - assert.Equal(t, Authentication{ - PlainText: &SaslPlainTextConfig{ - Username: "otel", - Password: "otel01$", - }, - }, primary.Auth) - assert.Equal(t, "queue://#trace-profile123", primary.Queue) - assert.Equal(t, uint32(1234), primary.MaxUnacked) - assert.Equal(t, configtls.TLSClientSetting{Insecure: false, InsecureSkipVerify: false}, primary.TLS) - - // validate backup config - backup := cfg.Receivers[config.NewComponentIDWithName(componentType, "backup")].(*Config) - assert.NotNil(t, backup) - assert.Equal(t, defaultHost, backup.Broker[0]) - assert.Equal(t, Authentication{ - XAuth2: &SaslXAuth2Config{ - Username: "otel", - Bearer: "otel01$", - }, - }, backup.Auth) - assert.Equal(t, "queue://#trace-profileABC", backup.Queue) - assert.Equal(t, defaultMaxUnaked, backup.MaxUnacked) - assert.Equal(t, configtls.TLSClientSetting{Insecure: true, InsecureSkipVerify: false}, backup.TLS) -} - -func TestLoadInvalidConfigMissingAuth(t *testing.T) { - factories := getTestNopFactories(t) - _, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config_invalid_noauth.yaml"), factories) - assert.Equal(t, errMissingAuthDetails, errors.Unwrap(err)) -} - -func TestLoadInvalidConfigMissingQueue(t *testing.T) { - factories := getTestNopFactories(t) - _, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config_invalid_noqueue.yaml"), factories) - assert.Equal(t, errMissingQueueName, errors.Unwrap(err)) -} - func TestCreateTracesReceiver(t *testing.T) { - factories := getTestNopFactories(t) - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - assert.NoError(t, err) - factory := factories.Receivers[componentType] - rcvCfg, ok := cfg.Receivers[config.NewComponentIDWithName(componentType, "primary")] - assert.True(t, ok) - receiver, err := factory.CreateTracesReceiver(context.Background(), componenttest.NewNopReceiverCreateSettings(), - rcvCfg, consumertest.NewNop()) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(config.NewComponentIDWithName(componentType, "primary").String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + receiver, err := factory.CreateTracesReceiver( + context.Background(), + componenttest.NewNopReceiverCreateSettings(), + cfg, + consumertest.NewNop(), + ) assert.NoError(t, err) castedReceiver, ok := receiver.(*solaceTracesReceiver) assert.True(t, ok) - assert.Equal(t, castedReceiver.config, rcvCfg) + assert.Equal(t, castedReceiver.config, cfg) } func TestCreateTracesReceiverWrongConfig(t *testing.T) { diff --git a/receiver/solacereceiver/testdata/config.yaml b/receiver/solacereceiver/testdata/config.yaml index 91d2a8fb68ff..62cc71d30981 100644 --- a/receiver/solacereceiver/testdata/config.yaml +++ b/receiver/solacereceiver/testdata/config.yaml @@ -1,31 +1,28 @@ -receivers: - solace/primary: - broker: [myHost:5671] - auth: - sasl_plain: - username: otel - password: otel01$ - queue: queue://#trace-profile123 - max_unacknowledged: 1234 - solace/backup: - auth: - sasl_xauth2: - username: otel - bearer: otel01$ - queue: queue://#trace-profileABC - tls: - insecure: true +solace/primary: + broker: [ myHost:5671 ] + auth: + sasl_plain: + username: otel + password: otel01$ + queue: queue://#trace-profile123 + max_unacknowledged: 1234 +solace/backup: + auth: + sasl_xauth2: + username: otel + bearer: otel01$ + queue: queue://#trace-profileABC + tls: + insecure: true -processors: - nop: +solace/noqueue: + broker: [ myHost:5671 ] + auth: + sasl_plain: + username: otel + password: otel01 -exporters: - nop: - -service: - pipelines: - traces: - receivers: [solace/primary, solace/backup] - processors: [nop] - exporters: [nop] +solace/noauth: + broker: [ myHost:5671 ] + queue: queue://#trace-profile123 diff --git a/receiver/solacereceiver/testdata/config_invalid_noauth.yaml b/receiver/solacereceiver/testdata/config_invalid_noauth.yaml deleted file mode 100644 index 639cc3caeaf2..000000000000 --- a/receiver/solacereceiver/testdata/config_invalid_noauth.yaml +++ /dev/null @@ -1,18 +0,0 @@ -receivers: - solace: - broker: [myHost:5671] - queue: queue://#trace-profile123 - - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [solace] - processors: [nop] - exporters: [nop] diff --git a/receiver/solacereceiver/testdata/config_invalid_noqueue.yaml b/receiver/solacereceiver/testdata/config_invalid_noqueue.yaml deleted file mode 100644 index 3a4aa4d1cbae..000000000000 --- a/receiver/solacereceiver/testdata/config_invalid_noqueue.yaml +++ /dev/null @@ -1,20 +0,0 @@ -receivers: - solace: - broker: [myHost:5671] - auth: - sasl_plain: - username: otel - password: otel01 - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [solace] - processors: [nop] - exporters: [nop]