Skip to content

Commit

Permalink
Add Test For Error In CreateMetricsReader
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Dec 1, 2024
1 parent 4842837 commit df0de70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin/metrics/prometheus/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (f *Factory) Initialize(telset telemetry.Settings) error {
func (f *Factory) CreateMetricsReader() (metricsstore.Reader, error) {
mr, err := prometheusstore.NewMetricsReader(f.options.Configuration, f.telset.Logger, f.telset.TracerProvider)
if err != nil {
return mr, err
return nil, err
}
return metricstoremetrics.NewReaderDecorator(mr, f.telset.Metrics), nil
}
Expand Down
9 changes: 9 additions & 0 deletions plugin/metrics/prometheus/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func TestPrometheusFactory(t *testing.T) {
assert.NotNil(t, reader)
}

func TestCreateMetricsReaderError(t *testing.T) {
f := NewFactory()
f.options.TLS.CAFile = "/does/not/exist"
require.NoError(t, f.Initialize(telemetry.NoopSettings()))
reader, err := f.CreateMetricsReader()
require.Error(t, err)
require.Nil(t, reader)
}

func TestWithDefaultConfiguration(t *testing.T) {
f := NewFactory()
assert.Equal(t, "http://localhost:9090", f.options.ServerURL)
Expand Down

0 comments on commit df0de70

Please sign in to comment.