Skip to content

Commit 279de2a

Browse files
committed
test(config): add test for writing default config.ini file and update test data
1 parent 7b4859a commit 279de2a

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Diff for: config/config_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,23 @@ func TestGetConfigPath(t *testing.T) {
8686
assert.Equal(t, wantContent, string(given))
8787
})
8888

89+
t.Run("write the default config.ini file", func(t *testing.T) {
90+
os.Setenv("HOME", "./testdata/fromdefault")
91+
os.Unsetenv("ARDUINO_CREATE_AGENT_CONFIG")
92+
93+
// ensure the config.ini does not exist in the target directory
94+
os.Remove("./testdata/fromdefault/.config/ArduinoCreateAgent/config.ini")
95+
96+
configPath := GetConfigPath()
97+
98+
assert.Equal(t, "testdata/fromdefault/.config/ArduinoCreateAgent/config.ini", configPath.String())
99+
100+
givenContent, err := paths.New(configPath.String()).ReadFile()
101+
if err != nil {
102+
t.Fatal(err)
103+
}
104+
105+
assert.Equal(t, configContent, givenContent)
106+
})
107+
89108
}

Diff for: config/testdata/fromdefault/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.ini

Diff for: config/testdata/fromenv/config.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
gc = std
2-
hostname = unknown-hostname
2+
hostname = this-is-a-config-file-from-home-dir-from-ARDUINO_CREATE_AGENT_CONFIG-env
33
regex = usb|acm|com
44
v = true
55
appName = CreateAgent/Stable

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
gc = std
2-
hostname = unknown-hostname
2+
hostname = this-is-a-config-file-from-home-dir
33
regex = usb|acm|com
44
v = true
55
appName = config-from-home-dir

0 commit comments

Comments
 (0)