Skip to content

Commit

Permalink
Refactor loop registry
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Jan 19, 2024
1 parent be8c68e commit 968b23d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/web/loop_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions plugins/config_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 5 additions & 0 deletions plugins/loop_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

0 comments on commit 968b23d

Please sign in to comment.