From 564f79f88076b0f95b50c6164ff8252a3e803f21 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Wed, 4 Oct 2023 16:57:25 -0500 Subject: [PATCH] pkg/services/servicetest: add helper for testing HealthReport names --- pkg/loop/relayer_service_test.go | 24 ++++++++++++++++++++++++ pkg/services/servicetest/health.go | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 pkg/services/servicetest/health.go diff --git a/pkg/loop/relayer_service_test.go b/pkg/loop/relayer_service_test.go index a0e44a13b9..43327f6fba 100644 --- a/pkg/loop/relayer_service_test.go +++ b/pkg/loop/relayer_service_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/loop" keystoretest "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/core/services/keystore/test" @@ -14,6 +16,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/test" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" "github.com/smartcontractkit/chainlink-common/pkg/types/core/mocks" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" ) func TestRelayerService(t *testing.T) { @@ -62,3 +65,24 @@ func TestRelayerService_recovery(t *testing.T) { relayertest.Run(t, relayer) } + +func TestRelayerService_HealthReport(t *testing.T) { + lggr := logger.Named(logger.Test(t), "Foo") + capRegistry := mocks.NewCapabilitiesRegistry(t) + s := loop.NewRelayerService(lggr, loop.GRPCOpts{}, func() *exec.Cmd { + return test.HelperProcessCommand{Command: loop.PluginRelayerName}.New() + }, test.ConfigTOML, keystoretest.Keystore, capRegistry) + + servicetest.AssertHealthReportNames(t, s.HealthReport(), + "Foo.RelayerService") + + require.NoError(t, s.Start(tests.Context(t))) + t.Cleanup(func() { require.NoError(t, s.Close()) }) + + require.Eventually(t, func() bool { return s.Ready() == nil }, tests.WaitTimeout(t)/2, time.Second, s.Ready()) + + servicetest.AssertHealthReportNames(t, s.HealthReport(), + "Foo.RelayerService", + "Foo.RelayerService.PluginRelayerClient.ChainRelayerClient", + "staticRelayer") +} diff --git a/pkg/services/servicetest/health.go b/pkg/services/servicetest/health.go new file mode 100644 index 0000000000..b43e0fe6e3 --- /dev/null +++ b/pkg/services/servicetest/health.go @@ -0,0 +1,17 @@ +package servicetest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" +) + +func AssertHealthReportNames(t *testing.T, hp map[string]error, names ...string) { + t.Helper() + keys := maps.Keys(hp) + slices.Sort(keys) + slices.Sort(names) + assert.EqualValues(t, names, keys) +}