Skip to content

Commit 063f4f8

Browse files
[skip-changelog] Some integration test refactorings (#1911)
* Integrated 'go.bug.st/testsuite' It doesn't make much sense to keep it separate in a different library * Do not use shared download dir for 'cache clean' command tests * Added method to get cli download dir * Create infra for sharing directories between tests * Slighlty improved test output * Non-parallel testing is no longer required * Add more time to complete tests * Update internal/integrationtest/cache/cache_test.go Co-authored-by: MatteoPologruto <[email protected]> Co-authored-by: MatteoPologruto <[email protected]>
1 parent 0e0b615 commit 063f4f8

File tree

14 files changed

+232
-29
lines changed

14 files changed

+232
-29
lines changed

Taskfile.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,12 @@ tasks:
9595
- task: go:build
9696
dir: '{{default "./" .GO_MODULE_PATH}}'
9797
cmds:
98-
# "-p 1" will not run test in parallel, this is required for integration tests
9998
- |
10099
go test \
101100
-v \
102101
-short \
103-
-p 1 \
104102
-run '{{default ".*" .GO_TEST_REGEX}}' \
105-
{{default "-timeout 15m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
103+
{{default "-timeout 20m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
106104
-coverprofile=coverage_unit.txt \
107105
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} \
108106
{{.TEST_LDFLAGS}}

arduino/discovery/discovery_client/go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ go.bug.st/relaxed-semver v0.9.0/go.mod h1:ug0/W/RPYUjliE70Ghxg77RDHmPxqpo7SHV16i
315315
go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg=
316316
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
317317
go.bug.st/testifyjson v1.1.1/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
318-
go.bug.st/testsuite v0.1.0/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
319318
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
320319
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
321320
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

client_example/go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ go.bug.st/relaxed-semver v0.9.0/go.mod h1:ug0/W/RPYUjliE70Ghxg77RDHmPxqpo7SHV16i
297297
go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg=
298298
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
299299
go.bug.st/testifyjson v1.1.1/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
300-
go.bug.st/testsuite v0.1.0/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
301300
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
302301
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
303302
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

docsgen/go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg=
373373
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI=
374374
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
375375
go.bug.st/testifyjson v1.1.1/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
376-
go.bug.st/testsuite v0.1.0/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
377376
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
378377
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
379378
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ require (
5858
)
5959

6060
require (
61+
github.com/rogpeppe/go-internal v1.3.0
6162
go.bug.st/testifyjson v1.1.1
62-
go.bug.st/testsuite v0.1.0
6363
)
6464

6565
require (

go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5H
310310
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
311311
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
312312
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
313+
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
313314
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
314315
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
315316
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -376,8 +377,6 @@ go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2
376377
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
377378
go.bug.st/testifyjson v1.1.1 h1:nHotIMK151LF3vYsU/b2RaoVaWCgrf2kvQeGNoZkGaA=
378379
go.bug.st/testifyjson v1.1.1/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
379-
go.bug.st/testsuite v0.1.0 h1:oX4zdIB62+G5A0Kq4dja7Vy8tDiKqKVhhxkzhpMGgog=
380-
go.bug.st/testsuite v0.1.0/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
381380
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
382381
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
383382
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

internal/integrationtest/arduino-cli.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,9 @@ import (
3333
"github.com/arduino/go-paths-helper"
3434
"github.com/fatih/color"
3535
"github.com/stretchr/testify/require"
36-
"go.bug.st/testsuite"
3736
"google.golang.org/grpc"
3837
)
3938

40-
func init() {
41-
testsuite.ProjectName = "cli"
42-
}
43-
4439
// FindRepositoryRootPath returns the repository root path
4540
func FindRepositoryRootPath(t *testing.T) *paths.Path {
4641
repoRootPath, err := paths.Getwd()
@@ -52,13 +47,18 @@ func FindRepositoryRootPath(t *testing.T) *paths.Path {
5247
return repoRootPath
5348
}
5449

50+
// FindArduinoCLIPath returns the path to the arduino-cli executable
51+
func FindArduinoCLIPath(t *testing.T) *paths.Path {
52+
return FindRepositoryRootPath(t).Join("arduino-cli")
53+
}
54+
5555
// CreateArduinoCLIWithEnvironment performs the minimum amount of actions
5656
// to build the default test environment.
57-
func CreateArduinoCLIWithEnvironment(t *testing.T) (*testsuite.Environment, *ArduinoCLI) {
58-
env := testsuite.NewEnvironment(t)
57+
func CreateArduinoCLIWithEnvironment(t *testing.T) (*Environment, *ArduinoCLI) {
58+
env := NewEnvironment(t)
5959

6060
cli := NewArduinoCliWithinEnvironment(env, &ArduinoCLIConfig{
61-
ArduinoCLIPath: FindRepositoryRootPath(t).Join("arduino-cli"),
61+
ArduinoCLIPath: FindArduinoCLIPath(t),
6262
UseSharedStagingFolder: true,
6363
})
6464

@@ -89,7 +89,7 @@ type ArduinoCLIConfig struct {
8989
}
9090

9191
// NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment.
92-
func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoCLIConfig) *ArduinoCLI {
92+
func NewArduinoCliWithinEnvironment(env *Environment, config *ArduinoCLIConfig) *ArduinoCLI {
9393
color.NoColor = false
9494
cli := &ArduinoCLI{
9595
path: config.ArduinoCLIPath,
@@ -100,7 +100,11 @@ func NewArduinoCliWithinEnvironment(env *testsuite.Environment, config *ArduinoC
100100
workingDir: env.RootDir(),
101101
}
102102
if config.UseSharedStagingFolder {
103-
cli.stagingDir = env.SharedDownloadsDir()
103+
sharedDir := env.SharedDownloadsDir()
104+
cli.stagingDir = sharedDir.Lock()
105+
env.RegisterCleanUpCallback(func() {
106+
sharedDir.Unlock()
107+
})
104108
}
105109

106110
cli.cliEnvVars = map[string]string{
@@ -137,6 +141,11 @@ func (cli *ArduinoCLI) WorkingDir() *paths.Path {
137141
return cli.workingDir
138142
}
139143

144+
// DownloadDir returns the download directory
145+
func (cli *ArduinoCLI) DownloadDir() *paths.Path {
146+
return cli.stagingDir
147+
}
148+
140149
// CopySketch copies a sketch inside the testing environment and returns its path
141150
func (cli *ArduinoCLI) CopySketch(sketchName string) *paths.Path {
142151
p, err := paths.Getwd()

internal/integrationtest/cache/cache_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ import (
2323
)
2424

2525
func TestCacheClean(t *testing.T) {
26-
// Clean the cache under arduino caching file directory which is "<Arduino configure file path>/staging"
27-
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
26+
// This test should not use shared download directory because it will be cleaned up with 'cache clean' command
27+
env := integrationtest.NewEnvironment(t)
28+
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
29+
ArduinoCLIPath: integrationtest.FindArduinoCLIPath(t),
30+
})
2831
defer env.CleanUp()
2932

3033
_, _, err := cli.Run("cache", "clean")

internal/integrationtest/config/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestInitWithExistingCustomConfig(t *testing.T) {
5050
require.Equal(t, config["board_manager"]["additional_urls"].([]interface{})[0].(string), "https://example.com")
5151
require.Equal(t, config["daemon"]["port"].(string), "50051")
5252
require.Equal(t, config["directories"]["data"].(string), cli.DataDir().String())
53-
require.Equal(t, config["directories"]["downloads"].(string), env.SharedDownloadsDir().String())
53+
require.Equal(t, config["directories"]["downloads"].(string), cli.DownloadDir().String())
5454
require.Equal(t, config["directories"]["user"].(string), cli.SketchbookDir().String())
5555
require.Empty(t, config["logging"]["file"])
5656
require.Equal(t, config["logging"]["format"].(string), "text")
@@ -71,7 +71,7 @@ func TestInitWithExistingCustomConfig(t *testing.T) {
7171
require.Empty(t, config["board_manager"]["additional_urls"])
7272
require.Equal(t, config["daemon"]["port"].(string), "50051")
7373
require.Equal(t, config["directories"]["data"].(string), cli.DataDir().String())
74-
require.Equal(t, config["directories"]["downloads"].(string), env.SharedDownloadsDir().String())
74+
require.Equal(t, config["directories"]["downloads"].(string), cli.DownloadDir().String())
7575
require.Equal(t, config["directories"]["user"].(string), cli.SketchbookDir().String())
7676
require.Empty(t, config["logging"]["file"])
7777
require.Equal(t, config["logging"]["format"].(string), "text")
@@ -96,7 +96,7 @@ func TestInitOverwriteExistingCustomFile(t *testing.T) {
9696
require.Equal(t, config["board_manager"]["additional_urls"].([]interface{})[0].(string), "https://example.com")
9797
require.Equal(t, config["daemon"]["port"].(string), "50051")
9898
require.Equal(t, config["directories"]["data"].(string), cli.DataDir().String())
99-
require.Equal(t, config["directories"]["downloads"].(string), env.SharedDownloadsDir().String())
99+
require.Equal(t, config["directories"]["downloads"].(string), cli.DownloadDir().String())
100100
require.Equal(t, config["directories"]["user"].(string), cli.SketchbookDir().String())
101101
require.Empty(t, config["logging"]["file"])
102102
require.Equal(t, config["logging"]["format"].(string), "text")
@@ -115,7 +115,7 @@ func TestInitOverwriteExistingCustomFile(t *testing.T) {
115115
require.Empty(t, config["board_manager"]["additional_urls"])
116116
require.Equal(t, config["daemon"]["port"].(string), "50051")
117117
require.Equal(t, config["directories"]["data"].(string), cli.DataDir().String())
118-
require.Equal(t, config["directories"]["downloads"].(string), env.SharedDownloadsDir().String())
118+
require.Equal(t, config["directories"]["downloads"].(string), cli.DownloadDir().String())
119119
require.Equal(t, config["directories"]["user"].(string), cli.SketchbookDir().String())
120120
require.Empty(t, config["logging"]["file"])
121121
require.Equal(t, config["logging"]["format"].(string), "text")

internal/integrationtest/daemon/daemon_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import (
2020

2121
"github.com/arduino/arduino-cli/internal/integrationtest"
2222
"github.com/stretchr/testify/require"
23-
"go.bug.st/testsuite"
2423
)
2524

2625
// createEnvForDaemon performs the minimum required operations to start the arduino-cli daemon.
2726
// It returns a testsuite.Environment and an ArduinoCLI client to perform the integration tests.
2827
// The Environment must be disposed by calling the CleanUp method via defer.
29-
func createEnvForDaemon(t *testing.T) (*testsuite.Environment, *integrationtest.ArduinoCLI) {
30-
env := testsuite.NewEnvironment(t)
28+
func createEnvForDaemon(t *testing.T) (*integrationtest.Environment, *integrationtest.ArduinoCLI) {
29+
env := integrationtest.NewEnvironment(t)
3130

3231
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
3332
ArduinoCLIPath: integrationtest.FindRepositoryRootPath(t).Join("arduino-cli"),

0 commit comments

Comments
 (0)