github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/pkg/plugin/cb/stats_collector_test.go (about) 1 package cb 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/hellofresh/stats-go/client" 9 ) 10 11 func TestCollector(t *testing.T) { 12 t.Parallel() 13 14 tests := []struct { 15 scenario string 16 function func(*testing.T) 17 }{ 18 { 19 scenario: "when a collector can be created", 20 function: testCollectorCreated, 21 }, 22 { 23 scenario: "when a collector cannot be created because the metrics client is nil", 24 function: testCollectorNotCreated, 25 }, 26 { 27 scenario: "when a collector registry is given", 28 function: testCollectorRegistry, 29 }, 30 } 31 32 for _, test := range tests { 33 t.Run(test.scenario, func(t *testing.T) { 34 test.function(t) 35 }) 36 } 37 } 38 39 func testCollectorCreated(t *testing.T) { 40 metricsClient := client.NewNoop() 41 _, err := NewStatsCollector("test", metricsClient) 42 43 require.NoError(t, err) 44 } 45 46 func testCollectorNotCreated(t *testing.T) { 47 _, err := NewStatsCollector("test", nil) 48 49 require.Error(t, err) 50 } 51 52 func testCollectorRegistry(t *testing.T) { 53 c := NewCollectorRegistry(client.NewNoop()) 54 require.NotNil(t, c) 55 56 c = NewCollectorRegistry(nil) 57 require.NotNil(t, c) 58 }