Skip to content

Commit 29a1bf3

Browse files
committed
refactor(config): remove default config file and update related tests
1 parent 716e8fc commit 29a1bf3

File tree

8 files changed

+29
-93
lines changed

8 files changed

+29
-93
lines changed

Diff for: config/config-default.ini

-10
This file was deleted.

Diff for: config/config_test.go

+22-54
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"testing"
66

7+
"github.com/arduino/go-paths-helper"
78
"github.com/stretchr/testify/assert"
89
)
910

@@ -25,68 +26,35 @@ func TestGetConfigPathFromHOME(t *testing.T) {
2526
}
2627

2728
func TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG(t *testing.T) {
28-
// read config from ARDUINO_CREATE_AGENT_CONFIG/config.ini"
29-
os.Setenv("HOME", "./fromhome")
30-
os.Setenv("ARDUINO_CREATE_AGENT_CONFIG", "./testdata/fromenv/config.ini")
29+
// $HOME must be always set, otherwise panic
30+
os.Setenv("HOME", "./testdata/dummyhome")
31+
32+
os.Setenv("ARDUINO_CREATE_AGENT_CONFIG", "./testdata/from-arduino-create-agent-config-env/config.ini")
3133
defer os.Unsetenv("ARDUINO_CREATE_AGENT_CONFIG")
3234

3335
configPath := GetConfigPath()
34-
assert.Equal(t, "./testdata/fromenv/config.ini", configPath.String())
36+
assert.Equal(t, "./testdata/from-arduino-create-agent-config-env/config.ini", configPath.String())
3537
}
3638

37-
// func TestGetConfigPathFromLegacyConfig(t *testing.T) {
38-
// // If no config is found, copy the legacy config to the new location
39-
// src, err := os.Executable()
40-
// if err != nil {
41-
// t.Fatal(err)
42-
// }
43-
// legacyConfigPath, err := paths.New(src).Parent().Join("config.ini").Create()
44-
// if err != nil {
45-
// t.Fatal(err)
46-
// }
47-
// // adding a timestamp to the content to make it unique
48-
// legacyContent := "hostname = legacy-config-file-" + time.Now().String()
49-
// n, err := legacyConfigPath.WriteString(legacyContent)
50-
// if err != nil || n <= 0 {
51-
// t.Fatalf("Failed to write legacy config file: %v", err)
52-
// }
53-
54-
// // remove any existing config.ini in the into the location pointed by $HOME
55-
// err = os.Remove("./testdata/fromlegacy/.config/ArduinoCreateAgent/config.ini")
56-
// if err != nil && !os.IsNotExist(err) {
57-
// t.Fatal(err)
58-
// }
59-
60-
// // Expectation: it copies the "legacy" config.ini into the location pointed by $HOME
61-
// os.Setenv("HOME", "./testdata/fromlegacy")
62-
// defer os.Unsetenv("HOME")
63-
64-
// configPath := GetConfigPath()
65-
// assert.Equal(t, "testdata/fromlegacy/.config/ArduinoCreateAgent/config.ini", configPath.String())
39+
// If the ARDUINO_CREATE_AGENT_CONFIG is NOT set and the config.ini does not exist in HOME directory
40+
// then it copies the default config (the config.ini) into the HOME directory
41+
func TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied(t *testing.T) {
42+
// $HOME must be always set, otherwise panic
43+
os.Setenv("HOME", "./testdata/home-without-config")
6644

67-
// given, err := paths.New(configPath.String()).ReadFile()
68-
// assert.Nil(t, err)
69-
// assert.Equal(t, legacyContent, string(given))
70-
// }
45+
os.Unsetenv("ARDUINO_CREATE_AGENT_CONFIG")
46+
// we want to test the case when the config does not exist in the home directory
47+
os.Remove("./testdata/home-without-config/.config/ArduinoCreateAgent/config.ini")
7148

72-
// func TestGetConfigPathCreateDefaultConfig(t *testing.T) {
73-
// os.Setenv("HOME", "./testdata/noconfig")
74-
// os.Unsetenv("ARDUINO_CREATE_AGENT_CONFIG")
75-
76-
// // ensure the config.ini does not exist in HOME directory
77-
// os.Remove("./testdata/noconfig/.config/ArduinoCreateAgent/config.ini")
78-
// // ensure the config.ini does not exist in target directory
79-
// os.Remove("./testdata/fromdefault/.config/ArduinoCreateAgent/config.ini")
80-
81-
// configPath := GetConfigPath()
49+
configPath := GetConfigPath()
8250

83-
// assert.Equal(t, "testdata/fromdefault/.config/ArduinoCreateAgent/config.ini", configPath.String())
51+
assert.Equal(t, "testdata/home-without-config/.config/ArduinoCreateAgent/config.ini", configPath.String())
8452

85-
// givenContent, err := paths.New(configPath.String()).ReadFile()
86-
// if err != nil {
87-
// t.Fatal(err)
88-
// }
53+
givenContent, err := paths.New(configPath.String()).ReadFile()
54+
if err != nil {
55+
t.Fatal(err)
56+
}
8957

90-
// assert.Equal(t, string(configContent), string(givenContent))
58+
assert.Equal(t, string(configContent), string(givenContent))
9159

92-
// }
60+
}

Diff for: config/testdata/fromenv/config.ini renamed to config/testdata/from-arduino-create-agent-config-env/config.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ regex = usb|acm|com
44
v = true
55
appName = CreateAgent/Stable
66
updateUrl = https://downloads.arduino.cc/
7-
origins = https://local.arduino.cc:8000, https://local.arduino.cc:8001, https://create-dev.arduino.cc, https://*.sparklyunicorn.cc, https://*.iot-cloud-arduino-cc.pages.dev, https://cloud.oniudra.cc, https://app.oniudra.cc,https://*.iot-cloud-arduino-cc.pages.dev
7+
origins = https://local.arduino.cc:8000, https://local.arduino.cc:8001
88
crashreport = false

Diff for: config/testdata/fromdefault/.gitignore

-1
This file was deleted.

Diff for: config/testdata/fromlegacy/.gitignore

-2
This file was deleted.
+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
gc = std # Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)
2-
hostname = unknown-hostname # Override the hostname we get from the OS
3-
regex = usb|acm|com # Regular expression to filter serial port list
4-
v = true # show debug logging
1+
gc = std
2+
hostname = this-is-a-config-file-from-xdghome-dir
3+
regex = usb|acm|com
4+
v = true
55
appName = CreateAgent/Stable
66
updateUrl = https://downloads.arduino.cc/
77
origins = https://local.arduino.cc:8000
8-
#httpProxy = http://your.proxy:port # Proxy server for HTTP requests
9-
crashreport = false # enable crashreport logging
10-
autostartMacOS = true # the Arduino Create Agent is able to start automatically after login on macOS (launchd agent)
8+
crashreport = false
9+
autostartMacOS = true

Diff for: config/testdata/home/.config/ArduinoCreateAgent/config.ini

-8
This file was deleted.

Diff for: config/testdata/noconfig/.config/ArduinoCreateAgent/config.ini

-10
This file was deleted.

0 commit comments

Comments
 (0)