@@ -99,6 +99,17 @@ func (te *TestEnvironment) Setup(
99
99
return err
100
100
}
101
101
102
+ // Need to always configure avalanchego. Even if using a
103
+ // persistent network, avalanchego is required for operations like
104
+ // node addition.
105
+ if avalancheGoExecPath != "" {
106
+ if _ , err := os .Stat (avalancheGoExecPath ); err != nil {
107
+ return fmt .Errorf ("could not find avalanchego binary: %w" , err )
108
+ }
109
+ }
110
+ te .avalancheGoExecPath = avalancheGoExecPath
111
+ te .avalancheGoLogLevel = avalancheGoLogLevel
112
+
102
113
// TODO(marun) Maybe lazy-load so that errors only fail dependent tests?
103
114
err = te .LoadKeys (testKeysFile )
104
115
if err != nil {
@@ -111,25 +122,13 @@ func (te *TestEnvironment) Setup(
111
122
tests .Outf ("{{yellow}}Using a pre-existing network{{/}}\n " )
112
123
113
124
// Read the URIs for the existing network so that tests can access the nodes.
114
-
115
125
err = te .refreshURIs ()
116
126
if err != nil {
117
127
return err
118
128
}
119
129
} else {
120
130
te .clusterType = StandAlone
121
131
122
- // Create a new network
123
-
124
- if avalancheGoExecPath != "" {
125
- if _ , err := os .Stat (avalancheGoExecPath ); err != nil {
126
- return fmt .Errorf ("could not find avalanchego binary: %w" , err )
127
- }
128
- }
129
-
130
- te .avalancheGoExecPath = avalancheGoExecPath
131
- te .avalancheGoLogLevel = avalancheGoLogLevel
132
-
133
132
err := te .startCluster ()
134
133
if err != nil {
135
134
return err
@@ -221,21 +220,30 @@ func (te *TestEnvironment) startCluster() error {
221
220
222
221
tests .Outf ("{{green}}successfully started network: {{/}} %+v\n " , resp .ClusterInfo .NodeNames )
223
222
224
- ctx , cancel = context .WithTimeout (context .Background (), 2 * time .Minute )
225
- _ , err = te .GetRunnerClient ().Health (ctx )
226
- cancel ()
223
+ err = te .CheckHealth ()
227
224
if err != nil {
228
- return fmt . Errorf ( "could not check network health: %w" , err )
225
+ return err
229
226
}
230
227
231
- tests .Outf ("{{green}}network reporting health{{/}}\n " )
232
-
233
228
te .isNetworkPristine = true
234
229
235
230
err = te .refreshURIs ()
236
231
return err
237
232
}
238
233
234
+ func (te * TestEnvironment ) CheckHealth () error {
235
+ ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Minute )
236
+ _ , err := te .GetRunnerClient ().Health (ctx )
237
+ cancel ()
238
+ if err != nil {
239
+ return fmt .Errorf ("could not check network health: %w" , err )
240
+ }
241
+
242
+ tests .Outf ("{{green}}network reporting health{{/}}\n " )
243
+
244
+ return nil
245
+ }
246
+
239
247
func (te * TestEnvironment ) refreshURIs () error {
240
248
ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Minute )
241
249
uriSlice , err := te .GetRunnerClient ().URIs (ctx )
@@ -365,3 +373,16 @@ func (te *TestEnvironment) Teardown() error {
365
373
tests .Outf ("{{red}}shutting down network-runner client{{/}}\n " )
366
374
return te .closeRunnerClient ()
367
375
}
376
+
377
+ func (te * TestEnvironment ) AddNode (name string , opts ... runner_sdk.OpOption ) error {
378
+ ctx , cancel := context .WithTimeout (context .Background (), DefaultShutdownTimeout )
379
+ _ , err := te .GetRunnerClient ().AddNode (ctx , name , te .avalancheGoExecPath , opts ... )
380
+ cancel ()
381
+ if err != nil {
382
+ return err
383
+ }
384
+
385
+ tests .Outf ("{{green}}added node %s{{/}}\n " , name )
386
+
387
+ return nil
388
+ }
0 commit comments