Skip to content

Commit a8d1734

Browse files
committed
testsuite: Pass cli config through env variables
1 parent 337f867 commit a8d1734

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

testsuite/arduino-cli.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type ArduinoCLI struct {
3636
path *paths.Path
3737
t *require.Assertions
3838
proc *executils.Process
39+
cliEnvVars []string
3940
cliConfigPath *paths.Path
4041
daemonAddr string
4142
daemonConn *grpc.ClientConn
@@ -45,17 +46,11 @@ type ArduinoCLI struct {
4546
// NewArduinoCliWithinEnvironment creates a new Arduino CLI client inside the given environment.
4647
func NewArduinoCliWithinEnvironment(t *testing.T, cliPath *paths.Path, env *Environment) *ArduinoCLI {
4748
cli := NewArduinoCli(t, cliPath)
48-
cli.cliConfigPath = env.Root().Join("arduino-cli.yaml")
49-
config := fmt.Sprintf(`
50-
directories:
51-
data: %s
52-
downloads: %s
53-
user: %s
54-
`,
55-
env.Root().Join("arduino15"),
56-
env.Root().Join("arduino15/staging"),
57-
env.Root().Join("Arduino"))
58-
require.NoError(t, cli.cliConfigPath.WriteFile([]byte(config)))
49+
cli.cliEnvVars = []string{
50+
fmt.Sprintf("ARDUINO_DATA_DIR=%s", env.Root().Join("arduino15")),
51+
fmt.Sprintf("ARDUINO_DOWNLOADS_DIR=%s", env.Root().Join("arduino15/staging")),
52+
fmt.Sprintf("ARDUINO_SKETCHBOOK_DIR=%s", env.Root().Join("Arduino")),
53+
}
5954
return cli
6055
}
6156

@@ -77,11 +72,11 @@ func (cli *ArduinoCLI) CleanUp() {
7772

7873
// Run executes the given arduino-cli command and returns the output.
7974
func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) {
80-
fmt.Println(color.HiBlackString(">>> Running: ") + color.HiYellowString("%s %s", cli.path, strings.Join(args, " ")))
8175
if cli.cliConfigPath != nil {
8276
args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...)
8377
}
84-
cliProc, err := executils.NewProcessFromPath(nil, cli.path, args...)
78+
fmt.Println(color.HiBlackString(">>> Running: ") + color.HiYellowString("%s %s", cli.path, strings.Join(args, " ")))
79+
cliProc, err := executils.NewProcessFromPath(cli.cliEnvVars, cli.path, args...)
8580
cli.t.NoError(err)
8681
stdout, err := cliProc.StdoutPipe()
8782
cli.t.NoError(err)

0 commit comments

Comments
 (0)