Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: FlamingSaint <[email protected]>
  • Loading branch information
FlamingSaint committed Jul 22, 2024
1 parent 7da08f3 commit 0aefd7b
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -56,17 +58,44 @@ func (e errorFactory) Close() error {
return e.closeErr
}

type errorMetricsFactory struct {

Check failure on line 61 in cmd/jaeger/internal/extension/jaegerstorage/extension_test.go

View workflow job for this annotation

GitHub Actions / lint

type `errorMetricsFactory` is unused (unused)
closeErr error
}

func (errorMetricsFactory) Initialize(*zap.Logger) error {

Check failure on line 65 in cmd/jaeger/internal/extension/jaegerstorage/extension_test.go

View workflow job for this annotation

GitHub Actions / lint

func `errorMetricsFactory.Initialize` is unused (unused)
panic("not implemented")
}

func (errorMetricsFactory) CreateMetricsReader() (metricsstore.Reader, error) {

Check failure on line 69 in cmd/jaeger/internal/extension/jaegerstorage/extension_test.go

View workflow job for this annotation

GitHub Actions / lint

func `errorMetricsFactory.CreateMetricsReader` is unused (unused)
panic("not implemented")
}

func (e errorMetricsFactory) Close() error {

Check failure on line 73 in cmd/jaeger/internal/extension/jaegerstorage/extension_test.go

View workflow job for this annotation

GitHub Actions / lint

func `errorMetricsFactory.Close` is unused (unused)
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{
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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: {
Expand All @@ -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())

Expand Down

0 comments on commit 0aefd7b

Please sign in to comment.