@@ -99,6 +99,17 @@ func (te *TestEnvironment) Setup(
9999 return err
100100 }
101101
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+
102113 // TODO(marun) Maybe lazy-load so that errors only fail dependent tests?
103114 err = te .LoadKeys (testKeysFile )
104115 if err != nil {
@@ -111,25 +122,13 @@ func (te *TestEnvironment) Setup(
111122 tests .Outf ("{{yellow}}Using a pre-existing network{{/}}\n " )
112123
113124 // Read the URIs for the existing network so that tests can access the nodes.
114-
115125 err = te .refreshURIs ()
116126 if err != nil {
117127 return err
118128 }
119129 } else {
120130 te .clusterType = StandAlone
121131
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-
133132 err := te .startCluster ()
134133 if err != nil {
135134 return err
@@ -221,21 +220,30 @@ func (te *TestEnvironment) startCluster() error {
221220
222221 tests .Outf ("{{green}}successfully started network: {{/}} %+v\n " , resp .ClusterInfo .NodeNames )
223222
224- ctx , cancel = context .WithTimeout (context .Background (), 2 * time .Minute )
225- _ , err = te .GetRunnerClient ().Health (ctx )
226- cancel ()
223+ err = te .CheckHealth ()
227224 if err != nil {
228- return fmt . Errorf ( "could not check network health: %w" , err )
225+ return err
229226 }
230227
231- tests .Outf ("{{green}}network reporting health{{/}}\n " )
232-
233228 te .isNetworkPristine = true
234229
235230 err = te .refreshURIs ()
236231 return err
237232}
238233
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+
239247func (te * TestEnvironment ) refreshURIs () error {
240248 ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Minute )
241249 uriSlice , err := te .GetRunnerClient ().URIs (ctx )
@@ -365,3 +373,16 @@ func (te *TestEnvironment) Teardown() error {
365373 tests .Outf ("{{red}}shutting down network-runner client{{/}}\n " )
366374 return te .closeRunnerClient ()
367375}
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