Skip to content

Commit f3d5212

Browse files
committed
transform raw TOML for all override mode
1 parent 1994028 commit f3d5212

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

framework/config.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func mergeInputs[T any]() (*T, error) {
8888
fmt.Println(string(data))
8989
}
9090

91+
data, err = transformAllOverrideModeForNodeSet(data)
92+
if err != nil {
93+
return nil, fmt.Errorf("error transforming node specs: %w", err)
94+
}
95+
9196
decoder := toml.NewDecoder(strings.NewReader(string(data)))
9297
decoder.DisallowUnknownFields()
9398

@@ -141,6 +146,41 @@ func validate(s interface{}) error {
141146
return nil
142147
}
143148

149+
// transformAllOverrideModeForNodeSet we need this function so the test logic can be the same in both "each" and "all" override modes
150+
// we can't do UnmarshalTOML or UnmarshalText because our TOML library do not support it
151+
func transformAllOverrideModeForNodeSet(data []byte) ([]byte, error) {
152+
var config map[string]interface{}
153+
if err := toml.Unmarshal(data, &config); err != nil {
154+
return nil, err
155+
}
156+
nodeset, ok := config["nodeset"].(map[string]interface{})
157+
if !ok {
158+
return data, nil
159+
}
160+
if nodeset["override_mode"] != "all" {
161+
return data, nil
162+
}
163+
nodes, ok := nodeset["nodes"].(int64)
164+
if !ok || nodes <= 0 {
165+
return nil, fmt.Errorf("invalid nodes count")
166+
}
167+
specs, ok := nodeset["node_specs"].([]interface{})
168+
if !ok || len(specs) == 0 {
169+
return nil, fmt.Errorf("node_specs must be provided")
170+
}
171+
firstSpec := specs[0].(map[string]interface{})
172+
expanded := make([]interface{}, nodes)
173+
for i := range expanded {
174+
newSpec := make(map[string]interface{})
175+
for k, v := range firstSpec {
176+
newSpec[k] = v
177+
}
178+
expanded[i] = newSpec
179+
}
180+
nodeset["node_specs"] = expanded
181+
return toml.Marshal(config)
182+
}
183+
144184
func Load[X any](t *testing.T) (*X, error) {
145185
input, err := mergeInputs[X]()
146186
if err != nil {

framework/examples/myproject/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ replace (
1111
require (
1212
github.com/block-vision/sui-go-sdk v1.0.6
1313
github.com/blocto/solana-go-sdk v1.30.0
14-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
14+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
1515
github.com/ethereum/go-ethereum v1.15.0
1616
github.com/go-resty/resty/v2 v2.16.3
1717
github.com/smartcontractkit/chainlink-testing-framework/framework v0.6.6
@@ -165,6 +165,7 @@ require (
165165
github.com/hashicorp/serf v0.10.1 // indirect
166166
github.com/holiman/uint256 v1.3.2 // indirect
167167
github.com/huandu/xstrings v1.5.0 // indirect
168+
github.com/jinzhu/copier v0.4.0 // indirect
168169
github.com/jmespath/go-jmespath v0.4.0 // indirect
169170
github.com/josharian/intern v1.0.0 // indirect
170171
github.com/jpillora/backoff v1.0.0 // indirect

framework/examples/myproject/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA=
700700
github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw=
701701
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
702702
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
703+
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
704+
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
703705
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
704706
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
705707
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=

framework/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ require (
105105
github.com/google/go-querystring v1.1.0 // indirect
106106
github.com/gorilla/websocket v1.5.1 // indirect
107107
github.com/holiman/uint256 v1.3.2 // indirect
108+
github.com/jinzhu/copier v0.4.0 // indirect
108109
github.com/json-iterator/go v1.1.12 // indirect
109110
github.com/klauspost/compress v1.17.4 // indirect
110111
github.com/klauspost/cpuid/v2 v2.2.8 // indirect

framework/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
246246
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
247247
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
248248
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
249+
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
250+
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
249251
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
250252
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
251253
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=

0 commit comments

Comments
 (0)