Skip to content

Commit

Permalink
add unit test for negative case
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-breen committed Oct 14, 2024
1 parent 2cb3674 commit f14b170
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions internal/collector/otel_collector_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,65 @@ func TestCollector_ProcessResourceUpdateTopic(t *testing.T) {
}
}

func TestCollector_ProcessResourceUpdateTopicFails(t *testing.T) {
conf := types.OTelConfig(t)
conf.Collector.Log.Path = ""
conf.Collector.Processors.Batch = nil
conf.Collector.Processors.Attribute = nil

tests := []struct {
message *bus.Message
processors config.Processors
name string
}{
{
name: "Test 1: Message cannot be parsed to v1.Resource",
message: &bus.Message{
Topic: bus.ResourceUpdateTopic,
Data: struct{}{},
},
},
}

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
collector, err := New(conf)
require.NoError(tt, err, "NewCollector should not return an error with valid config")

ctx := context.Background()
messagePipe := bus.NewMessagePipe(10)
err = messagePipe.Register(10, []bus.Plugin{collector})

require.NoError(tt, err)
require.NoError(tt, collector.Init(ctx, messagePipe), "Init should not return an error")
defer collector.Close(ctx)

assert.Eventually(
tt,
func() bool { return collector.service.GetState() == otelcol.StateRunning },
5*time.Second,
100*time.Millisecond,
)

collector.Process(ctx, test.message)

assert.Eventually(
tt,
func() bool { return collector.service.GetState() == otelcol.StateRunning },
5*time.Second,
100*time.Millisecond,
)

assert.Equal(tt,
config.Processors{
Batch: nil,
Attribute: nil,
},
collector.config.Collector.Processors)
})
}
}

// nolint: dupl
func TestCollector_updateExistingNginxOSSReceiver(t *testing.T) {
conf := types.OTelConfig(t)
Expand Down

0 comments on commit f14b170

Please sign in to comment.