From 3d5d3cf0ddae83399aa0578cabfd78263bac2e52 Mon Sep 17 00:00:00 2001 From: aalu1418 <50029043+aalu1418@users.noreply.github.com> Date: Wed, 17 Apr 2024 17:29:48 -0600 Subject: [PATCH] share naming + test cov --- cmd/monitoring/main.go | 16 ++++++---- pkg/monitoring/source_slotheight_test.go | 37 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 pkg/monitoring/source_slotheight_test.go diff --git a/cmd/monitoring/main.go b/cmd/monitoring/main.go index 64f1cefb2..cd87ae5f7 100644 --- a/cmd/monitoring/main.go +++ b/cmd/monitoring/main.go @@ -85,14 +85,18 @@ func main() { slotHeightSourceFactory, ) + // exporter names + promExporter := "solana-prom-exporter" + promMetrics := "solana-metrics" + // per-feed exporters feedBalancesExporterFactory := exporter.NewFeedBalancesFactory( - logger.With(log, "component", "solana-prom-exporter"), - metrics.NewFeedBalances(logger.With(log, "component", "solana-metrics")), + logger.With(log, "component", promExporter), + metrics.NewFeedBalances(logger.With(log, "component", promMetrics)), ) reportObservationsFactory := exporter.NewReportObservationsFactory( logger.With(log, "component", "solana-prome-exporter"), - metrics.NewReportObservations(logger.With(log, "component", "solana-metrics")), + metrics.NewReportObservations(logger.With(log, "component", promMetrics)), ) monitor.ExporterFactories = append(monitor.ExporterFactories, feedBalancesExporterFactory, @@ -101,12 +105,12 @@ func main() { // network exporters nodeBalancesExporterFactory := exporter.NewNodeBalancesFactory( - logger.With(log, "component", "solana-prom-exporter"), + logger.With(log, "component", promExporter), metrics.NewNodeBalances, ) slotHeightExporterFactory := exporter.NewSlotHeightFactory( - logger.With(log, "component", "solana-prom-exporter"), - metrics.NewSlotHeight(logger.With(log, "component", "solana-metrics")), + logger.With(log, "component", promExporter), + metrics.NewSlotHeight(logger.With(log, "component", promMetrics)), ) monitor.NetworkExporterFactories = append(monitor.NetworkExporterFactories, nodeBalancesExporterFactory, diff --git a/pkg/monitoring/source_slotheight_test.go b/pkg/monitoring/source_slotheight_test.go new file mode 100644 index 000000000..afd718c15 --- /dev/null +++ b/pkg/monitoring/source_slotheight_test.go @@ -0,0 +1,37 @@ +package monitoring + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils" + "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/mocks" + "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types" +) + +func TestSlotHeightSource(t *testing.T) { + cr := mocks.NewChainReader(t) + lgr := logger.Test(t) + ctx := utils.Context(t) + + factory := NewSlotHeightSourceFactory(cr, lgr) + assert.Equal(t, types.SlotHeightType, factory.GetType()) + + // generate source + source, err := factory.NewSource(nil, nil) + assert.Error(t, err) + source, err = factory.NewSource(nil, nil) + + cr.On("GetSlot", mock.Anything, mock.Anything, mock.Anything).Return(uint64(1), nil).Once() + + // happy path + out, err := source.Fetch(ctx) + require.NoError(t, err) + slot, ok := out.(types.SlotHeight) + require.True(t, ok) + assert.Equal(t, types.SlotHeight(1), slot) +}