Skip to content

Commit f1d4e79

Browse files
feat(deployment): add domain config getter abstraction
Add an Environment-level DomainConfigGetter interface with an os.Getenv-backed implementation, and cover default wiring plus getter behavior with focused deployment tests.
1 parent 8fd69b6 commit f1d4e79

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

deployment/domain_config_getter.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package deployment
2+
3+
import "os"
4+
5+
// DomainConfigGetter retrieves config values by key.
6+
type DomainConfigGetter interface {
7+
Get(key string) (value string, found bool)
8+
}
9+
10+
type envVarDomainConfigGetter struct{}
11+
12+
func (envVarDomainConfigGetter) Get(key string) (string, bool) {
13+
return os.LookupEnv(key)
14+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package deployment
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
//nolint:paralleltest // Mutates process-global env vars via os.Setenv.
11+
func TestEnvVarDomainConfigGetter_Get(t *testing.T) {
12+
const (
13+
key = "CLDF_TEST_DOMAIN_CONFIG_GETTER_KEY"
14+
value = "domain-config-value"
15+
)
16+
17+
prevValue, hadPrevValue := os.LookupEnv(key)
18+
require.NoError(t, os.Setenv(key, value))
19+
t.Cleanup(func() {
20+
if hadPrevValue {
21+
_ = os.Setenv(key, prevValue)
22+
return
23+
}
24+
_ = os.Unsetenv(key)
25+
})
26+
27+
var getter DomainConfigGetter = envVarDomainConfigGetter{}
28+
got, found := getter.Get(key)
29+
require.True(t, found)
30+
require.Equal(t, value, got)
31+
}

deployment/environment.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type Environment struct {
6060
OperationsBundle operations.Bundle
6161
// BlockChains is the container of all chains in the environment.
6262
BlockChains chain.BlockChains
63+
// DomainConfigGetter is used to read domain-backed configuration values.
64+
DomainConfigGetter DomainConfigGetter
6365
}
6466

6567
// EnvironmentOption is a functional option for configuring an Environment
@@ -88,8 +90,9 @@ func NewEnvironment(
8890
GetContext: ctx,
8991
OCRSecrets: secrets,
9092
// default to memory reporter as that is the only reporter available for now
91-
OperationsBundle: operations.NewBundle(ctx, logger, operations.NewMemoryReporter()),
92-
BlockChains: blockChains,
93+
OperationsBundle: operations.NewBundle(ctx, logger, operations.NewMemoryReporter()),
94+
BlockChains: blockChains,
95+
DomainConfigGetter: envVarDomainConfigGetter{},
9396
}
9497

9598
// Apply functional options
@@ -115,16 +118,17 @@ func (e Environment) Clone() Environment {
115118
}
116119

117120
return Environment{
118-
Name: e.Name,
119-
Logger: e.Logger,
120-
ExistingAddresses: ab,
121-
DataStore: ds.Seal(),
122-
NodeIDs: e.NodeIDs,
123-
Offchain: e.Offchain,
124-
GetContext: e.GetContext,
125-
OCRSecrets: e.OCRSecrets,
126-
OperationsBundle: e.OperationsBundle,
127-
BlockChains: e.BlockChains,
121+
Name: e.Name,
122+
Logger: e.Logger,
123+
ExistingAddresses: ab,
124+
DataStore: ds.Seal(),
125+
NodeIDs: e.NodeIDs,
126+
Offchain: e.Offchain,
127+
GetContext: e.GetContext,
128+
OCRSecrets: e.OCRSecrets,
129+
OperationsBundle: e.OperationsBundle,
130+
BlockChains: e.BlockChains,
131+
DomainConfigGetter: e.DomainConfigGetter,
128132
}
129133
}
130134

deployment/environment_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package deployment
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestNewEnvironment_DefaultDomainConfigGetter(t *testing.T) {
10+
t.Parallel()
11+
12+
env := NewNoopEnvironment(t)
13+
require.NotNil(t, env.DomainConfigGetter)
14+
}

0 commit comments

Comments
 (0)