Skip to content

Commit f5a9afc

Browse files
committed
feat(tests): enhance config tests with ini name checks and update test data
1 parent aaa97f9 commit f5a9afc

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

Diff for: config/config_linux_test.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/arduino/go-paths-helper"
9+
"github.com/go-ini/ini"
910
"github.com/stretchr/testify/assert"
1011
)
1112

@@ -18,7 +19,9 @@ func TestGetConfigPathFromXDG_CONFIG_HOME(t *testing.T) {
1819
os.Setenv("XDG_CONFIG_HOME", "./testdata/fromxdghome")
1920
defer os.Unsetenv("XDG_CONFIG_HOME")
2021
configPath := GetConfigPath()
22+
2123
assert.Equal(t, "testdata/fromxdghome/ArduinoCreateAgent/config.ini", configPath.String())
24+
checkIniName(t, configPath, "this-is-a-config-file-from-xdghome-dir")
2225
}
2326

2427
// TestGetConfigPathFromHOME tests the case when the config.ini is read from $HOME/.config/ArduinoCreateAgent/config.ini
@@ -29,8 +32,9 @@ func TestGetConfigPathFromHOME(t *testing.T) {
2932
os.Setenv("HOME", "./testdata/fromhome")
3033
defer os.Unsetenv("HOME")
3134
configPath := GetConfigPath()
32-
assert.Equal(t, "testdata/fromhome/.config/ArduinoCreateAgent/config.ini", configPath.String())
3335

36+
assert.Equal(t, "testdata/fromhome/.config/ArduinoCreateAgent/config.ini", configPath.String())
37+
checkIniName(t, configPath, "this-is-a-config-file-from-home-di")
3438
}
3539

3640
// TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG tests the case when the config.ini is read from ARDUINO_CREATE_AGENT_CONFIG env variable
@@ -46,7 +50,7 @@ func TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG(t *testing.T) {
4650

4751
configPath := GetConfigPath()
4852
assert.Equal(t, "./testdata/from-arduino-create-agent-config-env/config.ini", configPath.String())
49-
53+
checkIniName(t, configPath, "this-is-a-config-file-from-home-dir-from-ARDUINO_CREATE_AGENT_CONFIG-env")
5054
}
5155

5256
// TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied tests the case when the default config.ini is copied into $HOME/.config/ArduinoCreateAgent/config.ini
@@ -70,6 +74,7 @@ func TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied(t *testing.T) {
7074
configPath := GetConfigPath()
7175

7276
assert.Equal(t, "testdata/home-without-config/.config/ArduinoCreateAgent/config.ini", configPath.String())
77+
checkIniName(t, configPath, "") // the name of the default config is missing (an empty string)
7378

7479
givenContent, err := paths.New(configPath.String()).ReadFile()
7580
if err != nil {
@@ -79,3 +84,15 @@ func TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied(t *testing.T) {
7984
assert.Equal(t, string(configContent), string(givenContent))
8085

8186
}
87+
88+
func checkIniName(t *testing.T, confipath *paths.Path, expected string) {
89+
cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true, AllowPythonMultilineValues: true}, confipath.String())
90+
if err != nil {
91+
t.Fatal(err)
92+
}
93+
defaultSection, err := cfg.GetSection("")
94+
if err != nil {
95+
t.Fatal(err)
96+
}
97+
assert.Equal(t, expected, defaultSection.Key("name").String())
98+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
name = this-is-a-config-file-from-home-dir-from-ARDUINO_CREATE_AGENT_CONFIG-env
12
gc = std
2-
hostname = this-is-a-config-file-from-home-dir-from-ARDUINO_CREATE_AGENT_CONFIG-env
3+
hostname = an-hostname
34
regex = usb|acm|com
45
v = true
56
appName = CreateAgent/Stable
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
name = this-is-a-config-file-from-home-dir
12
gc = std
2-
hostname = this-is-a-config-file-from-home-dir
3+
hostname = an-hostname
34
regex = usb|acm|com
45
v = true
5-
appName = config-from-home-dir
6+
appName = an-app-n
67
updateUrl = https://downloads.arduino.cc/
78
origins = https://local.arduino.cc:8000, https://local.arduino.cc:8001, https://*.iot-cloud-arduino-cc.pages.dev
89
crashreport = false

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
name = this-is-a-config-file-from-xdghome-dir
12
gc = std
2-
hostname = this-is-a-config-file-from-xdghome-dir
3+
hostname = an-hostname
34
regex = usb|acm|com
45
v = true
56
appName = CreateAgent/Stable

0 commit comments

Comments
 (0)