Skip to content

Commit 8f304e3

Browse files
committed
testsuite: added some helpers to improve daemon testing
1 parent d43fe27 commit 8f304e3

File tree

3 files changed

+68
-29
lines changed

3 files changed

+68
-29
lines changed

Diff for: internal/integrationtest/arduino-cli.go

+26-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"os"
2424
"strings"
2525
"sync"
26-
"testing"
2726
"time"
2827

2928
"github.com/arduino/arduino-cli/executils"
@@ -42,6 +41,9 @@ type ArduinoCLI struct {
4241
proc *executils.Process
4342
cliEnvVars []string
4443
cliConfigPath *paths.Path
44+
stagingDir *paths.Path
45+
dataDir *paths.Path
46+
sketchbookDir *paths.Path
4547
daemonAddr string
4648
daemonConn *grpc.ClientConn
4749
daemonClient commands.ArduinoCoreServiceClient
@@ -56,28 +58,26 @@ type ArduinoCLIConfig struct {
5658
// NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment.
5759
func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoCLIConfig) *ArduinoCLI {
5860
color.NoColor = false
59-
cli := NewArduinoCli(env.T(), config)
60-
staging := env.SharedDownloadsDir()
61-
if !config.UseSharedStagingFolder {
62-
staging = env.RootDir().Join("arduino15/staging")
61+
cli := &ArduinoCLI{
62+
path: config.ArduinoCLIPath,
63+
t: require.New(env.T()),
64+
dataDir: env.RootDir().Join("arduino15"),
65+
sketchbookDir: env.RootDir().Join("Arduino"),
66+
stagingDir: env.RootDir().Join("arduino15/staging"),
6367
}
68+
if config.UseSharedStagingFolder {
69+
cli.stagingDir = env.SharedDownloadsDir()
70+
}
71+
6472
cli.cliEnvVars = []string{
65-
fmt.Sprintf("ARDUINO_DATA_DIR=%s", env.RootDir().Join("arduino15")),
66-
fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", staging),
67-
fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", env.RootDir().Join("Arduino")),
73+
fmt.Sprintf("ARDUINO_DATA_DIR=%s", cli.dataDir),
74+
fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", cli.stagingDir),
75+
fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", cli.sketchbookDir),
6876
}
6977
env.RegisterCleanUpCallback(cli.CleanUp)
7078
return cli
7179
}
7280

73-
// NewArduinoCli creates a new Arduino CLI client.
74-
func NewArduinoCli(t *testing.T, config *ArduinoCLIConfig) *ArduinoCLI {
75-
return &ArduinoCLI{
76-
path: config.ArduinoCLIPath,
77-
t: require.New(t),
78-
}
79-
}
80-
8181
// CleanUp closes the Arduino CLI client.
8282
func (cli *ArduinoCLI) CleanUp() {
8383
if cli.proc != nil {
@@ -86,6 +86,16 @@ func (cli *ArduinoCLI) CleanUp() {
8686
}
8787
}
8888

89+
// DataDir returns the data directory
90+
func (cli *ArduinoCLI) DataDir() *paths.Path {
91+
return cli.dataDir
92+
}
93+
94+
// SketchbookDir returns the sketchbook directory
95+
func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
96+
return cli.sketchbookDir
97+
}
98+
8999
// Run executes the given arduino-cli command and returns the output.
90100
func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) {
91101
if cli.cliConfigPath != nil {

Diff for: internal/integrationtest/daemon/arduino-cli_daemon_test.go

+2-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package integrationtest
16+
package daemon_test
1717

1818
import (
1919
"context"
@@ -22,28 +22,17 @@ import (
2222
"testing"
2323
"time"
2424

25-
"github.com/arduino/arduino-cli/internal/integrationtest"
2625
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
27-
"github.com/arduino/go-paths-helper"
2826
"github.com/stretchr/testify/require"
29-
"go.bug.st/testsuite"
3027
)
3128

3229
func TestArduinoCliDaemon(t *testing.T) {
3330
t.Skip("Deactivated for now")
3431
t.SkipNow()
3532

36-
env := testsuite.NewEnvironment(t)
33+
env, cli := createEnvForDaemon(t)
3734
defer env.CleanUp()
3835

39-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
40-
ArduinoCLIPath: paths.New("..", "..", "arduino-cli"),
41-
UseSharedStagingFolder: true,
42-
})
43-
44-
_, _, err := cli.Run("core", "update-index")
45-
require.NoError(t, err)
46-
4736
_ = cli.StartDaemon(false)
4837

4938
inst := cli.Create()

Diff for: internal/integrationtest/daemon/daemon_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package daemon_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/internal/integrationtest"
22+
"github.com/arduino/go-paths-helper"
23+
"github.com/stretchr/testify/require"
24+
"go.bug.st/testsuite"
25+
)
26+
27+
func createEnvForDaemon(t *testing.T) (*testsuite.Environment, *integrationtest.ArduinoCLI) {
28+
env := testsuite.NewEnvironment(t)
29+
30+
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
31+
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
32+
UseSharedStagingFolder: true,
33+
})
34+
35+
_, _, err := cli.Run("core", "update-index")
36+
require.NoError(t, err)
37+
38+
_ = cli.StartDaemon(false)
39+
return env, cli
40+
}

0 commit comments

Comments
 (0)