Skip to content

Commit 482f097

Browse files
committed
Made CreateEnvForDaeamon available in all integration tests
1 parent b7227b9 commit 482f097

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

internal/integrationtest/arduino-cli.go

+15
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ func NewArduinoCliWithinEnvironment(env *Environment, config *ArduinoCLIConfig)
122122
return cli
123123
}
124124

125+
// CreateEnvForDaemon performs the minimum required operations to start the arduino-cli daemon.
126+
// It returns a testsuite.Environment and an ArduinoCLI client to perform the integration tests.
127+
// The Environment must be disposed by calling the CleanUp method via defer.
128+
func CreateEnvForDaemon(t *testing.T) (*Environment, *ArduinoCLI) {
129+
env := NewEnvironment(t)
130+
131+
cli := NewArduinoCliWithinEnvironment(env, &ArduinoCLIConfig{
132+
ArduinoCLIPath: FindRepositoryRootPath(t).Join("arduino-cli"),
133+
UseSharedStagingFolder: true,
134+
})
135+
136+
_ = cli.StartDaemon(false)
137+
return env, cli
138+
}
139+
125140
// CleanUp closes the Arduino CLI client.
126141
func (cli *ArduinoCLI) CleanUp() {
127142
if cli.proc != nil {

internal/integrationtest/daemon/daemon_concurrency_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/arduino/arduino-cli/internal/integrationtest"
2627
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2728
"github.com/arduino/go-paths-helper"
2829
"github.com/stretchr/testify/require"
@@ -31,7 +32,7 @@ import (
3132
func TestArduinoCliDaemonCompileWithLotOfOutput(t *testing.T) {
3233
// See: https://github.com/arduino/arduino-cli/issues/2169
3334

34-
env, cli := createEnvForDaemon(t)
35+
env, cli := integrationtest.CreateEnvForDaemon(t)
3536
defer env.CleanUp()
3637

3738
_, _, err := cli.Run("core", "install", "arduino:avr")

internal/integrationtest/daemon/daemon_test.go

+11-26
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
func TestArduinoCliDaemon(t *testing.T) {
3838
// See: https://github.com/arduino/arduino-cli/pull/1804
3939

40-
env, cli := createEnvForDaemon(t)
40+
env, cli := integrationtest.CreateEnvForDaemon(t)
4141
defer env.CleanUp()
4242

4343
grpcInst := cli.Create()
@@ -96,7 +96,7 @@ func TestArduinoCliDaemon(t *testing.T) {
9696
func TestDaemonAutoUpdateIndexOnFirstInit(t *testing.T) {
9797
// https://github.com/arduino/arduino-cli/issues/1529
9898

99-
env, cli := createEnvForDaemon(t)
99+
env, cli := integrationtest.CreateEnvForDaemon(t)
100100
defer env.CleanUp()
101101

102102
grpcInst := cli.Create()
@@ -110,26 +110,11 @@ func TestDaemonAutoUpdateIndexOnFirstInit(t *testing.T) {
110110
require.FileExists(t, cli.DataDir().Join("package_index.json").String())
111111
}
112112

113-
// createEnvForDaemon performs the minimum required operations to start the arduino-cli daemon.
114-
// It returns a testsuite.Environment and an ArduinoCLI client to perform the integration tests.
115-
// The Environment must be disposed by calling the CleanUp method via defer.
116-
func createEnvForDaemon(t *testing.T) (*integrationtest.Environment, *integrationtest.ArduinoCLI) {
117-
env := integrationtest.NewEnvironment(t)
118-
119-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
120-
ArduinoCLIPath: integrationtest.FindRepositoryRootPath(t).Join("arduino-cli"),
121-
UseSharedStagingFolder: true,
122-
})
123-
124-
_ = cli.StartDaemon(false)
125-
return env, cli
126-
}
127-
128113
func TestDaemonCompileOptions(t *testing.T) {
129114
// See: https://github.com/arduino/arduino-cli/issues/1614
130115
// See: https://github.com/arduino/arduino-cli/pull/1820
131116

132-
env, cli := createEnvForDaemon(t)
117+
env, cli := integrationtest.CreateEnvForDaemon(t)
133118
defer env.CleanUp()
134119

135120
grpcInst := cli.Create()
@@ -203,7 +188,7 @@ func TestDaemonCompileOptions(t *testing.T) {
203188
func TestDaemonCompileAfterFailedLibInstall(t *testing.T) {
204189
// See: https://github.com/arduino/arduino-cli/issues/1812
205190

206-
env, cli := createEnvForDaemon(t)
191+
env, cli := integrationtest.CreateEnvForDaemon(t)
207192
defer env.CleanUp()
208193

209194
grpcInst := cli.Create()
@@ -233,7 +218,7 @@ func TestDaemonCompileAfterFailedLibInstall(t *testing.T) {
233218
}
234219

235220
func TestDaemonCoreUpdateIndex(t *testing.T) {
236-
env, cli := createEnvForDaemon(t)
221+
env, cli := integrationtest.CreateEnvForDaemon(t)
237222
defer env.CleanUp()
238223

239224
grpcInst := cli.Create()
@@ -269,7 +254,7 @@ func TestDaemonCoreUpdateIndex(t *testing.T) {
269254
}
270255

271256
func TestDaemonBundleLibInstall(t *testing.T) {
272-
env, cli := createEnvForDaemon(t)
257+
env, cli := integrationtest.CreateEnvForDaemon(t)
273258
defer env.CleanUp()
274259

275260
grpcInst := cli.Create()
@@ -409,7 +394,7 @@ func TestDaemonLibrariesRescanOnInstall(t *testing.T) {
409394
with the gprc instance
410395
The last attempt is expected to not raise an error
411396
*/
412-
env, cli := createEnvForDaemon(t)
397+
env, cli := integrationtest.CreateEnvForDaemon(t)
413398
defer env.CleanUp()
414399

415400
grpcInst := cli.Create()
@@ -465,7 +450,7 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) {
465450

466451
t.Run("upgraded successfully with additional urls", func(t *testing.T) {
467452
t.Run("and install.json is present", func(t *testing.T) {
468-
env, cli := createEnvForDaemon(t)
453+
env, cli := integrationtest.CreateEnvForDaemon(t)
469454
defer env.CleanUp()
470455

471456
grpcInst := cli.Create()
@@ -481,7 +466,7 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) {
481466
require.False(t, platform.Release.MissingMetadata) // install.json is present
482467
})
483468
t.Run("and install.json is missing", func(t *testing.T) {
484-
env, cli := createEnvForDaemon(t)
469+
env, cli := integrationtest.CreateEnvForDaemon(t)
485470
defer env.CleanUp()
486471

487472
grpcInst := cli.Create()
@@ -504,7 +489,7 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) {
504489

505490
t.Run("upgrade failed", func(t *testing.T) {
506491
t.Run("without additional URLs", func(t *testing.T) {
507-
env, cli := createEnvForDaemon(t)
492+
env, cli := integrationtest.CreateEnvForDaemon(t)
508493
defer env.CleanUp()
509494

510495
grpcInst := cli.Create()
@@ -524,7 +509,7 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) {
524509
require.False(t, platform.Release.MissingMetadata) // install.json is present
525510
})
526511
t.Run("missing both additional URLs and install.json", func(t *testing.T) {
527-
env, cli := createEnvForDaemon(t)
512+
env, cli := integrationtest.CreateEnvForDaemon(t)
528513
defer env.CleanUp()
529514

530515
grpcInst := cli.Create()

0 commit comments

Comments
 (0)