Skip to content

Commit

Permalink
pkg/services/servicetest: add helper for testing HealthReport names
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Jan 14, 2025
1 parent 0cd7b49 commit 6aceb1f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/loop/relayer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
}
17 changes: 17 additions & 0 deletions pkg/services/servicetest/health.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 6aceb1f

Please sign in to comment.