From df0de7082f583c25a5bbfe15cf37abbeb50a80e1 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sun, 1 Dec 2024 14:10:55 -0500 Subject: [PATCH] Add Test For Error In CreateMetricsReader Signed-off-by: Mahad Zaryab --- plugin/metrics/prometheus/factory.go | 2 +- plugin/metrics/prometheus/factory_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/metrics/prometheus/factory.go b/plugin/metrics/prometheus/factory.go index aaa47c7d86f..8aaa0d2e1af 100644 --- a/plugin/metrics/prometheus/factory.go +++ b/plugin/metrics/prometheus/factory.go @@ -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 } diff --git a/plugin/metrics/prometheus/factory_test.go b/plugin/metrics/prometheus/factory_test.go index b74c8354d80..c14778928d5 100644 --- a/plugin/metrics/prometheus/factory_test.go +++ b/plugin/metrics/prometheus/factory_test.go @@ -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)