From 0aefd7b91f3bf62633e78e4ab43437fc2353541e Mon Sep 17 00:00:00 2001 From: FlamingSaint Date: Mon, 22 Jul 2024 22:42:31 +0530 Subject: [PATCH] Increase code coverage Signed-off-by: FlamingSaint --- .../extension/jaegerstorage/extension_test.go | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go index b05ef36474a..c9388f37d37 100644 --- a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go +++ b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go @@ -23,12 +23,14 @@ import ( esCfg "github.com/jaegertracing/jaeger/pkg/es/config" "github.com/jaegertracing/jaeger/pkg/metrics" + promCfg "github.com/jaegertracing/jaeger/pkg/prometheus/config" "github.com/jaegertracing/jaeger/plugin/storage/badger" "github.com/jaegertracing/jaeger/plugin/storage/cassandra" "github.com/jaegertracing/jaeger/plugin/storage/grpc" "github.com/jaegertracing/jaeger/plugin/storage/memory" "github.com/jaegertracing/jaeger/storage" "github.com/jaegertracing/jaeger/storage/dependencystore" + "github.com/jaegertracing/jaeger/storage/metricsstore" "github.com/jaegertracing/jaeger/storage/spanstore" ) @@ -56,17 +58,44 @@ func (e errorFactory) Close() error { return e.closeErr } +type errorMetricsFactory struct { + closeErr error +} + +func (errorMetricsFactory) Initialize(*zap.Logger) error { + panic("not implemented") +} + +func (errorMetricsFactory) CreateMetricsReader() (metricsstore.Reader, error) { + panic("not implemented") +} + +func (e errorMetricsFactory) Close() error { + return e.closeErr +} + func TestStorageFactoryBadHostError(t *testing.T) { _, err := GetStorageFactory("something", componenttest.NewNopHost()) require.ErrorContains(t, err, "cannot find extension") } func TestStorageFactoryBadNameError(t *testing.T) { - host := storagetest.NewStorageHost().WithExtension(ID, startStorageExtension(t, "foo")) + host := storagetest.NewStorageHost().WithExtension(ID, startStorageExtension(t, "foo", "")) _, err := GetStorageFactory("bar", host) require.ErrorContains(t, err, "cannot find definition of storage 'bar'") } +func TestMetricsFactoryBadHostError(t *testing.T) { + _, err := GetMetricsFactory("something", componenttest.NewNopHost()) + require.ErrorContains(t, err, "cannot find extension") +} + +func TestMetricsFactoryBadNameError(t *testing.T) { + host := storagetest.NewStorageHost().WithExtension(ID, startStorageExtension(t, "", "foo")) + _, err := GetMetricsFactory("bar", host) + require.ErrorContains(t, err, "cannot find metric storage 'bar'") +} + func TestStorageFactoryBadShutdownError(t *testing.T) { shutdownError := fmt.Errorf("shutdown error") ext := storageExt{ @@ -86,7 +115,8 @@ func TestGetFactoryV2Error(t *testing.T) { func TestGetFactory(t *testing.T) { const name = "foo" - host := storagetest.NewStorageHost().WithExtension(ID, startStorageExtension(t, name)) + const metricname = "bar" + host := storagetest.NewStorageHost().WithExtension(ID, startStorageExtension(t, name, metricname)) f, err := GetStorageFactory(name, host) require.NoError(t, err) require.NotNil(t, f) @@ -132,6 +162,22 @@ func TestGRPC(t *testing.T) { require.NoError(t, ext.Shutdown(ctx)) } +func TestPrometheus(t *testing.T) { + ext := makeStorageExtenion(t, &Config{ + MetricBackends: map[string]MetricBackends{ + "foo": { + Prometheus: &promCfg.Configuration{ + ServerURL: "localhost:12345", + }, + }, + }, + }) + ctx := context.Background() + err := ext.Start(ctx, componenttest.NewNopHost()) + require.NoError(t, err) + require.NoError(t, ext.Shutdown(ctx)) +} + func TestStartError(t *testing.T) { ext := makeStorageExtenion(t, &Config{ Backends: map[string]Backend{ @@ -222,7 +268,7 @@ func makeStorageExtenion(t *testing.T, config *Config) component.Component { return ext } -func startStorageExtension(t *testing.T, memstoreName string) component.Component { +func startStorageExtension(t *testing.T, memstoreName string, promstoreName string) component.Component { config := &Config{ Backends: map[string]Backend{ memstoreName: { @@ -231,6 +277,13 @@ func startStorageExtension(t *testing.T, memstoreName string) component.Componen }, }, }, + MetricBackends: map[string]MetricBackends{ + promstoreName: { + Prometheus: &promCfg.Configuration{ + ServerURL: "localhost:12345", + }, + }, + }, } require.NoError(t, config.Validate())