Skip to content

Commit 8634233

Browse files
authored
feat: add WithName option for test environment loader (#1002)
Allow tests to set a custom environment name via `WithName`, falling back to the default name when unset. The default name has also been exposed as a public constant
1 parent 8cc4fdb commit 8634233

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

engine/test/environment/components.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
type components struct {
1717
mu sync.Mutex
1818

19+
Name string
1920
Chains []fchain.BlockChain
2021
AddressBook fdeployment.AddressBook
2122
Datastore fdatastore.DataStore

engine/test/environment/environment.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
const (
19-
environmentName = "test_environment"
19+
DefaultEnvironmentName = "test_environment"
2020
)
2121

2222
// New creates a new environment for testing.
@@ -67,9 +67,14 @@ func (l *Loader) Load(ctx context.Context, opts ...LoadOpt) (*fdeployment.Enviro
6767
oc = foffchain.NewMemoryJobDistributor()
6868
}
6969

70+
name := cmps.Name
71+
if name == "" {
72+
name = DefaultEnvironmentName
73+
}
74+
7075
// CRERunner may be nil; tests that need CRE use WithCRERunner(cre.NewRunner(cre.WithCLI(cremocks.NewMockCLIRunner(t)))).
7176
return &fdeployment.Environment{
72-
Name: environmentName,
77+
Name: name,
7378
Logger: cmps.Logger,
7479
BlockChains: fchain.NewBlockChainsFromSlice(cmps.Chains),
7580
ExistingAddresses: ab,

engine/test/environment/environment_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ func TestLoader_Load_NodeIDsOption(t *testing.T) {
151151
require.Equal(t, nodeIDs, env.NodeIDs)
152152
}
153153

154+
func TestLoader_Load_NameOption(t *testing.T) {
155+
t.Parallel()
156+
157+
name := "test-name"
158+
loader := NewLoader()
159+
env, err := loader.Load(t.Context(), WithName(name))
160+
require.NoError(t, err)
161+
require.NotNil(t, env)
162+
require.Equal(t, name, env.Name)
163+
}
164+
154165
func TestLoader_Load_AddressBookOption(t *testing.T) {
155166
t.Parallel()
156167

engine/test/environment/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ func WithNodeIDs(nodeIDs []string) LoadOpt {
234234
}
235235
}
236236

237+
// WithName sets the name for the environment.
238+
func WithName(name string) LoadOpt {
239+
return func(cmps *components) error {
240+
cmps.Name = name
241+
return nil
242+
}
243+
}
244+
237245
// withChainLoader creates a LoadOpt that loads chains using the provided loader and selectors.
238246
func withChainLoader(t *testing.T, loader *onchain.ChainLoader, selectors []uint64) LoadOpt {
239247
t.Helper()

0 commit comments

Comments
 (0)