Skip to content

Commit 3b35366

Browse files
committed
simplify configuration of nodeset and components
1 parent 713bfc3 commit 3b35366

File tree

9 files changed

+230
-371
lines changed

9 files changed

+230
-371
lines changed

framework/clclient/client.go

Lines changed: 67 additions & 68 deletions
Large diffs are not rendered by default.

framework/cmd/main.go

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ func main() {
3333
{
3434
Name: "config",
3535
Aliases: []string{"c"},
36-
Usage: "Shapes your test config, removes outputs",
36+
Usage: "Shapes your test config, removes outputs, formatting ,etc",
3737
Subcommands: []*cli.Command{
3838
{
39-
Name: "cleanup",
40-
Aliases: []string{"c"},
41-
Usage: "Clean up the outputs of any test configuration",
39+
Name: "fmt",
40+
Aliases: []string{"f"},
41+
Usage: "Formats TOML config",
4242
Action: func(c *cli.Context) error {
4343
in := c.Args().Get(0)
44-
return CleanupToml(in, in)
44+
return PrettyPrintTOML(in, in)
4545
},
4646
},
4747
},
@@ -210,8 +210,8 @@ func observabilityDown() error {
210210
return nil
211211
}
212212

213-
// CleanupToml removes any paths in the TOML tree that contain "out" and writes the result to a new file.
214-
func CleanupToml(inputFile string, outputFile string) error {
213+
// PrettyPrintTOML pretty prints TOML
214+
func PrettyPrintTOML(inputFile string, outputFile string) error {
215215
tomlData, err := os.ReadFile(inputFile)
216216
if err != nil {
217217
return fmt.Errorf("error reading file: %v", err)
@@ -221,9 +221,6 @@ func CleanupToml(inputFile string, outputFile string) error {
221221
return fmt.Errorf("error parsing TOML: %v", err)
222222
}
223223

224-
// Recursively remove fields/paths that contain "out"
225-
removeOutFields(tree)
226-
227224
// Write the result to a new file
228225
dumpData, err := tree.ToTomlString()
229226
if err != nil {
@@ -237,43 +234,3 @@ func CleanupToml(inputFile string, outputFile string) error {
237234
framework.L.Info().Str("File", outputFile).Msg("File cleaned up and saved")
238235
return nil
239236
}
240-
241-
// removeOutFields recursively removes any table, array of tables, or key path containing "out"
242-
func removeOutFields(tree *toml.Tree) {
243-
keys := tree.Keys()
244-
245-
for _, key := range keys {
246-
value := tree.Get(key)
247-
248-
// If the key contains framework.OutputFieldNameTOML, delete the whole path
249-
if hasOutputField(key) {
250-
_ = tree.Delete(key)
251-
continue
252-
}
253-
254-
switch v := value.(type) {
255-
// Handle regular tables recursively
256-
case *toml.Tree:
257-
removeOutFields(v)
258-
if len(v.Keys()) == 0 {
259-
_ = tree.Delete(key)
260-
}
261-
// Handle arrays of tables
262-
case []*toml.Tree:
263-
for i := len(v) - 1; i >= 0; i-- {
264-
removeOutFields(v[i])
265-
if len(v[i].Keys()) == 0 {
266-
v = append(v[:i], v[i+1:]...)
267-
}
268-
}
269-
if len(v) == 0 {
270-
_ = tree.Delete(key)
271-
}
272-
}
273-
}
274-
}
275-
276-
func hasOutputField(key string) bool {
277-
return len(key) > 0 && (key == framework.OutputFieldNameTOML ||
278-
len(key) > 3 && key[len(key)-3:] == framework.OutputFieldNameTOML)
279-
}

framework/components/blockchain/anvil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func deployAnvil(in *Input) (*Output, error) {
2424

2525
req := testcontainers.ContainerRequest{
2626
AlwaysPullImage: in.PullImage,
27-
Image: fmt.Sprintf("%s:%s", in.Image, in.Tag),
27+
Image: fmt.Sprintf("%s", in.Image),
2828
Labels: framework.DefaultTCLabels(),
2929
Name: containerName,
3030
ExposedPorts: []string{bindPort},

framework/components/blockchain/blockchain.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
type Input struct {
99
Type string `toml:"type" validate:"required,oneof=anvil geth" envconfig:"net_type"`
1010
Image string `toml:"image" validate:"required"`
11-
Tag string `toml:"tag" validate:"required"`
12-
PullImage bool `toml:"pull_image" default:"true"`
13-
Port string `toml:"port" validate:"required" default:"8545"`
14-
ChainID string `toml:"chain_id" validate:"required" default:"31337"`
11+
PullImage bool `toml:"pull_image"`
12+
Port string `toml:"port" validate:"required"`
13+
ChainID string `toml:"chain_id" validate:"required"`
1514
DockerCmdParamsOverrides []string `toml:"docker_cmd_params"`
1615
Out *Output `toml:"out"`
1716
}
@@ -35,7 +34,7 @@ type Node struct {
3534
// - Anvil
3635
// - Geth
3736
func NewBlockchainNetwork(in *Input) (*Output, error) {
38-
if in.Out.UseCache {
37+
if in.Out != nil && in.Out.UseCache {
3938
return in.Out, nil
4039
}
4140
var out *Output

framework/components/clnode/clnode.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,28 @@ import (
1515
"time"
1616
)
1717

18+
const (
19+
Port = "6688"
20+
P2PPort = "6690"
21+
)
22+
1823
// Input represents Chainlink node input
1924
type Input struct {
20-
DataProviderURL string `toml:"data_provider_url" validate:"required" default:"http://host.docker.internal:9111"`
25+
DataProviderURL string `toml:"data_provider_url" validate:"required"`
2126
DbInput *postgres.Input `toml:"db" validate:"required"`
2227
Node *NodeInput `toml:"node" validate:"required"`
2328
Out *Output `toml:"out"`
2429
}
2530

2631
// NodeInput is CL nod container inputs
2732
type NodeInput struct {
28-
Image string `toml:"image" validate:"required"`
29-
Tag string `toml:"tag" validate:"required"`
30-
Name string `toml:"name"`
31-
PullImage bool `toml:"pull_image" default:"true"`
32-
Port string `toml:"port" validate:"required" default:"6688"`
33-
P2PPort string `toml:"p2p_port" validate:"required" default:"6690"`
33+
Image string `toml:"image" validate:"required"`
34+
Name string `toml:"name"`
35+
PullImage bool `toml:"pull_image"`
36+
//Port string `toml:"port" validate:"required"`
37+
//P2PPort string `toml:"p2p_port" validate:"required"`
3438
CapabilitiesBinaryPaths []string `toml:"capabilities"`
35-
CapabilityContainerDir string `toml:"capabilities_container_dir" default:"/home/capabilities"`
39+
CapabilityContainerDir string `toml:"capabilities_container_dir"`
3640
TestConfigOverrides string `toml:"test_config_overrides"`
3741
UserConfigOverrides string `toml:"user_config_overrides"`
3842
TestSecretsOverrides string `toml:"test_secrets_overrides"`
@@ -130,8 +134,8 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
130134
return nil, err
131135
}
132136

133-
httpPort := fmt.Sprintf("%s/tcp", in.Node.Port)
134-
p2pPort := fmt.Sprintf("%s/udp", in.Node.P2PPort)
137+
httpPort := fmt.Sprintf("%s/tcp", Port)
138+
p2pPort := fmt.Sprintf("%s/udp", P2PPort)
135139
var containerName string
136140
if in.Node.Name != "" {
137141
containerName = in.Node.Name
@@ -141,7 +145,7 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
141145

142146
req := tc.ContainerRequest{
143147
AlwaysPullImage: in.Node.PullImage,
144-
Image: fmt.Sprintf("%s:%s", in.Node.Image, in.Node.Tag),
148+
Image: fmt.Sprintf("%s", in.Node.Image),
145149
Name: containerName,
146150
Labels: framework.DefaultTCLabels(),
147151
Networks: []string{framework.DefaultNetworkName},
@@ -230,8 +234,8 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
230234
return &NodeOut{
231235
HostURL: fmt.Sprintf("http://%s:%s", host, mp.Port()),
232236
HostP2PURL: fmt.Sprintf("http://%s:%s", host, mpP2P.Port()),
233-
DockerURL: fmt.Sprintf("http://%s:%s", containerName, in.Node.Port),
234-
DockerP2PUrl: fmt.Sprintf("http://%s:%s", containerName, in.Node.P2PPort),
237+
DockerURL: fmt.Sprintf("http://%s:%s", containerName, Port),
238+
DockerP2PUrl: fmt.Sprintf("http://%s:%s", containerName, P2PPort),
235239
}, nil
236240
}
237241

@@ -242,7 +246,7 @@ type DefaultCLNodeConfig struct {
242246

243247
func generateDefaultConfig(in *Input) (string, error) {
244248
config := DefaultCLNodeConfig{
245-
HTTPPort: in.Node.Port,
249+
HTTPPort: Port,
246250
SecureCookies: false,
247251
}
248252
tmpl, err := template.New("toml").Parse(defaultConfigTmpl)

framework/components/node_set_extended/node_set_extended.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

framework/components/postgres/postgres.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import (
1212
"time"
1313
)
1414

15+
const (
16+
User = "chainlink"
17+
Password = "thispasswordislongenough"
18+
Port = "5432"
19+
Database = "chainlink"
20+
Databases = 20
21+
)
22+
1523
type Input struct {
16-
Image string `toml:"image" validate:"required" default:"postgres"`
17-
Tag string `toml:"tag" validate:"required" default:"15.6"`
18-
PullImage bool `toml:"pull_image" default:"true"`
19-
User string `toml:"user" validate:"required" default:"chainlink"`
20-
Password string `toml:"password" validate:"required" default:"thispasswordislongenough"`
21-
Database string `toml:"database" validate:"required" default:"chainlink"`
22-
Databases int `toml:"databases" validate:"required" default:"20"`
23-
Port string `toml:"port" validate:"required" default:"5432"`
24+
Image string `toml:"image" validate:"required"`
25+
PullImage bool `toml:"pull_image"`
2426
Out *Output `toml:"out"`
2527
}
2628

@@ -32,12 +34,12 @@ type Output struct {
3234
func NewPostgreSQL(in *Input) (*Output, error) {
3335
ctx := context.Background()
3436

35-
bindPort := fmt.Sprintf("%s/tcp", in.Port)
37+
bindPort := fmt.Sprintf("%s/tcp", Port)
3638

3739
containerName := framework.DefaultTCName("postgresql")
3840

3941
var sqlCommands []string
40-
for i := 0; i <= in.Databases; i++ {
42+
for i := 0; i <= Databases; i++ {
4143
sqlCommands = append(sqlCommands, fmt.Sprintf("CREATE DATABASE db_%d;", i))
4244
}
4345
sqlCommands = append(sqlCommands, "ALTER USER chainlink WITH SUPERUSER;")
@@ -55,7 +57,7 @@ func NewPostgreSQL(in *Input) (*Output, error) {
5557

5658
req := testcontainers.ContainerRequest{
5759
AlwaysPullImage: in.PullImage,
58-
Image: fmt.Sprintf("%s:%s", in.Image, in.Tag),
60+
Image: fmt.Sprintf("%s", in.Image),
5961
Name: containerName,
6062
Labels: framework.DefaultTCLabels(),
6163
ExposedPorts: []string{bindPort},
@@ -64,12 +66,12 @@ func NewPostgreSQL(in *Input) (*Output, error) {
6466
framework.DefaultNetworkName: {containerName},
6567
},
6668
Env: map[string]string{
67-
"POSTGRES_USER": in.User,
68-
"POSTGRES_PASSWORD": in.Password,
69-
"POSTGRES_DB": in.Database,
69+
"POSTGRES_USER": User,
70+
"POSTGRES_PASSWORD": Password,
71+
"POSTGRES_DB": Database,
7072
},
7173
Cmd: []string{
72-
"postgres", "-c", fmt.Sprintf("port=%s", in.Port),
74+
"postgres", "-c", fmt.Sprintf("port=%s", Port),
7375
},
7476
Files: []testcontainers.ContainerFile{
7577
{
@@ -79,7 +81,7 @@ func NewPostgreSQL(in *Input) (*Output, error) {
7981
},
8082
},
8183
WaitingFor: tcwait.ForExec([]string{"psql", "-h", "127.0.0.1",
82-
"-U", in.User, "-p", in.Port, "-c", "select", "1", "-d", in.Database}).
84+
"-U", User, "-p", Port, "-c", "select", "1", "-d", Database}).
8385
WithStartupTimeout(20 * time.Second),
8486
}
8587
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
@@ -100,19 +102,19 @@ func NewPostgreSQL(in *Input) (*Output, error) {
100102
return &Output{
101103
DockerInternalURL: fmt.Sprintf(
102104
"postgresql://%s:%s@%s:%s/%s?sslmode=disable",
103-
in.User,
104-
in.Password,
105+
User,
106+
Password,
105107
containerName,
106-
in.Port,
107-
in.Database,
108+
Port,
109+
Database,
108110
),
109111
Url: fmt.Sprintf(
110112
"postgresql://%s:%s@%s:%s/%s?sslmode=disable",
111-
in.User,
112-
in.Password,
113+
User,
114+
Password,
113115
host,
114116
mp.Port(),
115-
in.Database,
117+
Database,
116118
),
117119
}, nil
118120
}

0 commit comments

Comments
 (0)