Skip to content

Commit a863c50

Browse files
author
Massimiliano Pippi
committed
fix integration tests
1 parent 2d66c29 commit a863c50

File tree

5 files changed

+20
-55
lines changed

5 files changed

+20
-55
lines changed

Diff for: cli/cli.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ func preRun(cmd *cobra.Command, args []string) {
150150
}
151151

152152
// override the config path if --config-file was passed
153-
if configFile != "" {
154-
configPath = filepath.Dir(configFile)
153+
if fi, err := os.Stat(configFile); err == nil {
154+
if fi.IsDir() {
155+
configPath = configFile
156+
} else {
157+
configPath = filepath.Dir(configFile)
158+
}
155159
}
156160

157161
// initialize the config system

Diff for: cli/cli_test.go

+8-52
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"runtime"
2929
"testing"
3030

31+
"github.com/spf13/viper"
32+
3133
"github.com/arduino/arduino-cli/cli/feedback"
3234

3335
"bou.ke/monkey"
@@ -128,25 +130,10 @@ func executeWithArgs(args ...string) (int, []byte) {
128130
var output []byte
129131
var exitCode int
130132
fmt.Printf("RUNNING: %s\n", args)
133+
viper.Reset()
131134

132135
// This closure is here because we won't that the defer are executed after the end of the "executeWithArgs" method
133136
func() {
134-
// Create an empty config for the CLI test in the same dir of the test
135-
conf := paths.New("arduino-cli.yaml")
136-
if conf.Exist() {
137-
panic("config file must not exist already")
138-
}
139-
140-
if err := conf.WriteFile([]byte("board_manager:\n additional_urls:\n")); err != nil {
141-
panic(err)
142-
}
143-
144-
defer func() {
145-
if err := conf.Remove(); err != nil {
146-
panic(err)
147-
}
148-
}()
149-
150137
redirect := &stdOutRedirect{}
151138
redirect.Open()
152139
// re-init feedback so it'll write to our grabber
@@ -365,28 +352,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
365352
}
366353

367354
func TestInvalidCoreURLIntegration(t *testing.T) {
368-
// override SetUp dirs
369-
tmp := tmpDirOrDie()
370-
defer os.RemoveAll(tmp)
371-
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp)
372-
currSketchbookDir = tmp
373-
374-
configFile := filepath.Join(currDataDir, "arduino-cli.yaml")
375-
err := ioutil.WriteFile(configFile, []byte(`
376-
board_manager:
377-
additional_urls:
378-
- http://www.invalid-domain-asjkdakdhadjkh.com/package_example_index.json
379-
`), os.FileMode(0644))
380-
require.NoError(t, err, "writing dummy config "+configFile)
381-
382-
err = ioutil.WriteFile(filepath.Join(currDataDir, "package_index.json"), []byte(`{ "packages": [] }`), os.FileMode(0644))
383-
require.NoError(t, err, "Writing empty json index file")
384-
385-
err = ioutil.WriteFile(filepath.Join(currDataDir, "package_example_index.json"), []byte(`{ "packages": [] }`), os.FileMode(0644))
386-
require.NoError(t, err, "Writing empty json index file")
387-
388-
err = ioutil.WriteFile(filepath.Join(currDataDir, "library_index.json"), []byte(`{ "libraries": [] }`), os.FileMode(0644))
389-
require.NoError(t, err, "Writing empty json index file")
355+
configFile := filepath.Join("testdata", t.Name())
390356

391357
// Dump config with cmd-line specific file
392358
exitCode, d := executeWithArgs("--config-file", configFile, "config", "dump")
@@ -399,19 +365,7 @@ board_manager:
399365
}
400366

401367
func Test3rdPartyCoreIntegration(t *testing.T) {
402-
// override SetUp dirs
403-
tmp := tmpDirOrDie()
404-
defer os.RemoveAll(tmp)
405-
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp)
406-
currSketchbookDir = tmp
407-
408-
configFile := filepath.Join(currDataDir, "arduino-cli.yaml")
409-
err := ioutil.WriteFile(configFile, []byte(`
410-
board_manager:
411-
additional_urls:
412-
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
413-
`), os.FileMode(0644))
414-
require.NoError(t, err, "writing dummy config "+configFile)
368+
configFile := filepath.Join("testdata", t.Name())
415369

416370
// Update index and install esp32:esp32
417371
exitCode, _ := executeWithArgs("--config-file", configFile, "core", "update-index")
@@ -422,7 +376,7 @@ board_manager:
422376

423377
// Build a simple sketch and check if all artifacts are copied
424378
tmpSketch := paths.New(currSketchbookDir).Join("Blink")
425-
err = paths.New("testdata/Blink").CopyDirTo(tmpSketch)
379+
err := paths.New("testdata/Blink").CopyDirTo(tmpSketch)
426380
require.NoError(t, err, "copying test sketch into temp dir")
427381
exitCode, d = executeWithArgs("--config-file", configFile, "compile", "-b", "esp32:esp32:esp32", tmpSketch.String())
428382
require.Zero(t, exitCode)
@@ -543,13 +497,15 @@ func TestSearchConfigTreeNotFound(t *testing.T) {
543497

544498
func TestSearchConfigTreeSameFolder(t *testing.T) {
545499
tmp := tmpDirOrDie()
500+
defer os.RemoveAll(tmp)
546501
_, err := os.Create(filepath.Join(tmp, "arduino-cli.yaml"))
547502
require.Nil(t, err)
548503
require.Equal(t, searchConfigTree(tmp), tmp)
549504
}
550505

551506
func TestSearchConfigTreeInParent(t *testing.T) {
552507
tmp := tmpDirOrDie()
508+
defer os.RemoveAll(tmp)
553509
target := filepath.Join(tmp, "foo", "bar")
554510
err := os.MkdirAll(target, os.ModePerm)
555511
require.Nil(t, err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
board_manager:
2+
additional_urls:
3+
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
board_manager:
2+
additional_urls:
3+
- http://www.invalid-domain-asjkdakdhadjkh.com/package_example_index.json

Diff for: go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/cmaglie/pb v1.0.27
1313
github.com/codeclysm/cc v1.2.2 // indirect
1414
github.com/codeclysm/extract v2.2.0+incompatible
15-
github.com/creack/goselect v0.0.0-20180328191401-176c667f75aa // indirect
1615
github.com/fatih/color v1.7.0
1716
github.com/fluxio/iohelpers v0.0.0-20160419043813-3a4dd67a94d2 // indirect
1817
github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5 // indirect

0 commit comments

Comments
 (0)