Skip to content

Commit aa41d72

Browse files
[skip-changelog] Refactoring of the testsuite environment (#1852)
* testsuite: added functions to setup arduino-cli integration tests * Moved 'requiredjson' library in his own package * Modified tests in cache_test.go to use the new arduino-cli setup * Modified tests in main_test.go to use the new arduino-cli setup Co-authored-by: Cristian Maglie <c.maglie@arduino.cc>
1 parent 63f1e18 commit aa41d72

File tree

10 files changed

+49
-59
lines changed

10 files changed

+49
-59
lines changed

arduino/discovery/discovery_client/go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ go.bug.st/downloader/v2 v2.1.1/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13R
314314
go.bug.st/relaxed-semver v0.9.0/go.mod h1:ug0/W/RPYUjliE70Ghxg77RDHmPxqpo7SHV16ijss7Q=
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=
317-
go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
317+
go.bug.st/testifyjson v1.0.0/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
318+
go.bug.st/testsuite v0.1.0/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
318319
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
319320
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
320321
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

client_example/go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ go.bug.st/downloader/v2 v2.1.1/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13R
296296
go.bug.st/relaxed-semver v0.9.0/go.mod h1:ug0/W/RPYUjliE70Ghxg77RDHmPxqpo7SHV16ijss7Q=
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=
299-
go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
299+
go.bug.st/testifyjson v1.0.0/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
300+
go.bug.st/testsuite v0.1.0/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
300301
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
301302
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
302303
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

docsgen/go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ go.bug.st/serial v1.3.2 h1:6BFZZd/wngoL5PPYYTrFUounF54SIkykHpT98eq6zvk=
372372
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=
375-
go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
375+
go.bug.st/testifyjson v1.0.0/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
376+
go.bug.st/testsuite v0.1.0/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
376377
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
377378
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
378379
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ require (
5757
gopkg.in/yaml.v2 v2.4.0
5858
)
5959

60-
require go.bug.st/testsuite v0.0.1
60+
require (
61+
go.bug.st/testifyjson v1.0.0
62+
go.bug.st/testsuite v0.1.0
63+
)
6164

6265
require (
6366
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,10 @@ go.bug.st/serial v1.3.2 h1:6BFZZd/wngoL5PPYYTrFUounF54SIkykHpT98eq6zvk=
374374
go.bug.st/serial v1.3.2/go.mod h1:jDkjqASf/qSjmaOxHSHljwUQ6eHo/ZX/bxJLQqSlvZg=
375375
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI=
376376
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw=
377-
go.bug.st/testsuite v0.0.1 h1:sdB+u46r+9ZVqROU1fl5utU773HktWDSc4hz6/jPK6A=
378-
go.bug.st/testsuite v0.0.1/go.mod h1:xCIDf97kf9USoz960Foy3CoquwhQmfuFRNh9git70as=
377+
go.bug.st/testifyjson v1.0.0 h1:eO7y5Qwziia+vyiaMFlnm5D40NMtkd7quSB7lJtcrjw=
378+
go.bug.st/testifyjson v1.0.0/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=
379381
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
380382
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
381383
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=

internal/integrationtest/arduino-cli.go

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

2829
"github.com/arduino/arduino-cli/executils"
@@ -34,6 +35,30 @@ import (
3435
"google.golang.org/grpc"
3536
)
3637

38+
// FindRepositoryRootPath returns the repository root path
39+
func FindRepositoryRootPath(t *testing.T) *paths.Path {
40+
repoRootPath := paths.New(".")
41+
require.NoError(t, repoRootPath.ToAbs())
42+
for !repoRootPath.Join(".git").Exist() {
43+
require.Contains(t, repoRootPath.String(), "arduino-cli", "Error searching for repository root path")
44+
repoRootPath = repoRootPath.Parent()
45+
}
46+
return repoRootPath
47+
}
48+
49+
// CreateArduinoCLIWithEnvironment performs the minimum amount of actions
50+
// to build the default test environment.
51+
func CreateArduinoCLIWithEnvironment(t *testing.T) (*testsuite.Environment, *ArduinoCLI) {
52+
env := testsuite.NewEnvironment(t)
53+
54+
cli := NewArduinoCliWithinEnvironment(env, &ArduinoCLIConfig{
55+
ArduinoCLIPath: FindRepositoryRootPath(t).Join("arduino-cli"),
56+
UseSharedStagingFolder: true,
57+
})
58+
59+
return env, cli
60+
}
61+
3762
// ArduinoCLI is an Arduino CLI client.
3863
type ArduinoCLI struct {
3964
path *paths.Path

internal/integrationtest/cache/cache_test.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,14 @@ import (
1919
"testing"
2020

2121
"github.com/arduino/arduino-cli/internal/integrationtest"
22-
"github.com/arduino/go-paths-helper"
2322
"github.com/stretchr/testify/require"
24-
"go.bug.st/testsuite"
2523
)
2624

2725
func TestCacheClean(t *testing.T) {
2826
// Clean the cache under arduino caching file directory which is "<Arduino configure file path>/staging"
29-
30-
env := testsuite.NewEnvironment(t)
27+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
3128
defer env.CleanUp()
3229

33-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
34-
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
35-
UseSharedStagingFolder: true,
36-
})
37-
3830
_, _, err := cli.Run("cache", "clean")
3931
require.NoError(t, err)
4032

internal/integrationtest/core/core_list_test.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@ import (
2121
"github.com/arduino/arduino-cli/internal/integrationtest"
2222
"github.com/arduino/go-paths-helper"
2323
"github.com/stretchr/testify/require"
24-
"go.bug.st/testsuite"
25-
"go.bug.st/testsuite/requirejson"
24+
"go.bug.st/testifyjson/requirejson"
2625
)
2726

2827
func TestCorrectHandlingOfPlatformVersionProperty(t *testing.T) {
2928
// See: https://github.com/arduino/arduino-cli/issues/1823
30-
31-
env := testsuite.NewEnvironment(t)
29+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
3230
defer env.CleanUp()
3331

34-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
35-
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
36-
UseSharedStagingFolder: true,
37-
})
38-
3932
// Copy test platform
4033
testPlatform := paths.New("testdata", "issue_1823", "DxCore-dev")
4134
require.NoError(t, testPlatform.CopyDirTo(cli.SketchbookDir().Join("hardware", "DxCore-dev")))

internal/integrationtest/core/core_test.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,13 @@ import (
2323
"github.com/arduino/arduino-cli/internal/integrationtest"
2424
"github.com/arduino/go-paths-helper"
2525
"github.com/stretchr/testify/require"
26-
"go.bug.st/testsuite"
27-
"go.bug.st/testsuite/requirejson"
26+
"go.bug.st/testifyjson/requirejson"
2827
)
2928

3029
func TestCoreSearch(t *testing.T) {
31-
env := testsuite.NewEnvironment(t)
30+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
3231
defer env.CleanUp()
3332

34-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
35-
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
36-
UseSharedStagingFolder: true,
37-
})
38-
3933
// Set up an http server to serve our custom index file
4034
test_index := paths.New("..", "testdata", "test_index.json")
4135
url := env.HTTPServeFile(8000, test_index)

internal/integrationtest/main/main_test.go

+5-27
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,15 @@ import (
2121
"testing"
2222

2323
"github.com/arduino/arduino-cli/internal/integrationtest"
24-
"github.com/arduino/go-paths-helper"
2524
"github.com/stretchr/testify/require"
2625
semver "go.bug.st/relaxed-semver"
27-
"go.bug.st/testsuite"
28-
"go.bug.st/testsuite/requirejson"
26+
"go.bug.st/testifyjson/requirejson"
2927
)
3028

3129
func TestHelp(t *testing.T) {
32-
env := testsuite.NewEnvironment(t)
30+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
3331
defer env.CleanUp()
3432

35-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
36-
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
37-
UseSharedStagingFolder: true,
38-
})
39-
4033
// Run help and check the output message
4134
stdout, stderr, err := cli.Run("help")
4235
require.NoError(t, err)
@@ -45,14 +38,9 @@ func TestHelp(t *testing.T) {
4538
}
4639

4740
func TestVersion(t *testing.T) {
48-
env := testsuite.NewEnvironment(t)
41+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
4942
defer env.CleanUp()
5043

51-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
52-
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
53-
UseSharedStagingFolder: true,
54-
})
55-
5644
// Run version and check the output message
5745
stdout, stderr, err := cli.Run("version")
5846
require.NoError(t, err)
@@ -87,14 +75,9 @@ func TestVersion(t *testing.T) {
8775

8876
func TestLogOptions(t *testing.T) {
8977
// Using version as a test command
90-
env := testsuite.NewEnvironment(t)
78+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
9179
defer env.CleanUp()
9280

93-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
94-
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
95-
UseSharedStagingFolder: true,
96-
})
97-
9881
// No logs
9982
stdout, _, err := cli.Run("version")
10083
require.NoError(t, err)
@@ -143,14 +126,9 @@ func TestLogOptions(t *testing.T) {
143126

144127
func TestInventoryCreation(t *testing.T) {
145128
// Using version as a test command
146-
env := testsuite.NewEnvironment(t)
129+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
147130
defer env.CleanUp()
148131

149-
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
150-
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
151-
UseSharedStagingFolder: true,
152-
})
153-
154132
// no logs
155133
stdout, _, err := cli.Run("version")
156134
require.NoError(t, err)

0 commit comments

Comments
 (0)