From 968b23d79a1cde89bfcc55304e4f504dfd5b169a Mon Sep 17 00:00:00 2001 From: Cedric Cordenier Date: Mon, 15 Jan 2024 17:42:52 +0000 Subject: [PATCH] Refactor loop registry --- core/web/loop_registry_test.go | 2 +- plugins/config_test.go | 33 +++++++++++++++++++++++++++++++++ plugins/loop_registry_test.go | 5 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 plugins/config_test.go diff --git a/core/web/loop_registry_test.go b/core/web/loop_registry_test.go index ee75986e3aa..b28f625bd50 100644 --- a/core/web/loop_registry_test.go +++ b/core/web/loop_registry_test.go @@ -84,7 +84,7 @@ func TestLoopRegistry(t *testing.T) { require.NoError(t, app.Start(testutils.Context(t))) // register a mock loop - loop, err := app.GetLoopRegistry().Register("mockLoopImpl", "NOOP-COMMAND") + loop, err := app.GetLoopRegistry().Register("mockLoopImpl", "./COMMAND") require.NoError(t, err) require.NotNil(t, loop) require.Len(t, app.GetLoopRegistry().List(), 1) diff --git a/plugins/config_test.go b/plugins/config_test.go new file mode 100644 index 00000000000..22d70eff682 --- /dev/null +++ b/plugins/config_test.go @@ -0,0 +1,33 @@ +package plugins + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/loop" + "github.com/smartcontractkit/chainlink/v2/core/logger" +) + +func TestRegistrarConfig(t *testing.T) { + mockCfgTracing := &MockCfgTracing{} + registry := make(map[string]*RegisteredLoop) + + // Create a LoopRegistry instance with mockCfgTracing + loopRegistry := &LoopRegistry{ + lggr: logger.TestLogger(t), + registry: registry, + cfgTracing: mockCfgTracing, + } + + opts := loop.GRPCOpts{} + rConf := NewRegistrarConfig(opts, loopRegistry.Register) + + assert.Equal(t, opts, rConf.GRPCOpts()) + + id := "command-id" + rl, err := rConf.RegisterLOOP(id, "./COMMAND") + require.NoError(t, err) + assert.Equal(t, registry[id], rl) +} diff --git a/plugins/loop_registry_test.go b/plugins/loop_registry_test.go index 558585185c6..ba3c9cb0312 100644 --- a/plugins/loop_registry_test.go +++ b/plugins/loop_registry_test.go @@ -3,6 +3,7 @@ package plugins import ( "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -59,4 +60,8 @@ func TestLoopRegistry_Register(t *testing.T) { require.Equal(t, map[string]string{"attribute": "value"}, registeredLoop.EnvCfg.TracingAttributes) require.Equal(t, 0.1, registeredLoop.EnvCfg.TracingSamplingRatio) require.Equal(t, "/path/to/cert.pem", registeredLoop.EnvCfg.TracingTLSCertPath) + + gc := registeredLoop.Cmd() + assert.Equal(t, "./COMMAND", gc.Path) + assert.ElementsMatch(t, registeredLoop.EnvCfg.AsCmdEnv(), gc.Env) }