diff --git a/receiver/podmanreceiver/config_test.go b/receiver/podmanreceiver/config_test.go index af10cde71b25..c3c7a8fdde03 100644 --- a/receiver/podmanreceiver/config_test.go +++ b/receiver/podmanreceiver/config_test.go @@ -24,9 +24,9 @@ func TestLoadConfig(t *testing.T) { require.NoError(t, err) tests := []struct { - id component.ID - expected component.Config - expectedErr error + id component.ID + expected component.Config + expectedErrMsg string }{ { id: component.NewIDWithName(metadata.Type, ""), @@ -54,6 +54,14 @@ func TestLoadConfig(t *testing.T) { MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), }, }, + { + id: component.NewIDWithName(metadata.Type, "empty_endpoint"), + expectedErrMsg: "config.Endpoint must be specified", + }, + { + id: component.NewIDWithName(metadata.Type, "invalid_collection_interval"), + expectedErrMsg: `config.CollectionInterval must be specified; "collection_interval": requires positive value`, + }, } for _, tt := range tests { @@ -65,6 +73,11 @@ func TestLoadConfig(t *testing.T) { require.NoError(t, err) require.NoError(t, sub.Unmarshal(cfg)) + if tt.expectedErrMsg != "" { + assert.EqualError(t, component.ValidateConfig(cfg), tt.expectedErrMsg) + return + } + assert.NoError(t, component.ValidateConfig(cfg)) assert.Equal(t, tt.expected, cfg) }) diff --git a/receiver/podmanreceiver/receiver.go b/receiver/podmanreceiver/receiver.go index cfca7b87f228..0590ae59c07b 100644 --- a/receiver/podmanreceiver/receiver.go +++ b/receiver/podmanreceiver/receiver.go @@ -66,11 +66,6 @@ func createMetricsReceiver( } func (r *metricsReceiver) start(ctx context.Context, _ component.Host) error { - err := r.config.Validate() - if err != nil { - return err - } - podmanClient, err := r.clientFactory(r.set.Logger, r.config) if err != nil { return err diff --git a/receiver/podmanreceiver/receiver_test.go b/receiver/podmanreceiver/receiver_test.go index a56ab487f0cf..e14f660bc3b4 100644 --- a/receiver/podmanreceiver/receiver_test.go +++ b/receiver/podmanreceiver/receiver_test.go @@ -37,13 +37,7 @@ func TestErrorsInStart(t *testing.T) { assert.NotNil(t, recv) err := recv.start(context.Background(), componenttest.NewNopHost()) require.Error(t, err) - assert.Equal(t, "config.Endpoint must be specified", err.Error()) - - recv = newMetricsReceiver(receivertest.NewNopSettings(), &Config{Endpoint: "someEndpoint"}, nil) - assert.NotNil(t, recv) - err = recv.start(context.Background(), componenttest.NewNopHost()) - require.Error(t, err) - assert.Equal(t, "config.CollectionInterval must be specified", err.Error()) + assert.Equal(t, `unable to create connection. "" is not a supported schema`, err.Error()) } func TestScraperLoop(t *testing.T) { diff --git a/receiver/podmanreceiver/testdata/config.yaml b/receiver/podmanreceiver/testdata/config.yaml index 1912e5a53c7f..2fe85451e483 100644 --- a/receiver/podmanreceiver/testdata/config.yaml +++ b/receiver/podmanreceiver/testdata/config.yaml @@ -3,3 +3,7 @@ podman_stats/all: endpoint: http://example.com/ collection_interval: 2s timeout: 20s +podman_stats/empty_endpoint: + endpoint: "" +podman_stats/invalid_collection_interval: + collection_interval: 0s