@@ -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
367354func 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
401367func 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
544498func 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
551506func 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 )
0 commit comments