6
6
"testing"
7
7
8
8
"github.com/arduino/go-paths-helper"
9
+ "github.com/go-ini/ini"
9
10
"github.com/stretchr/testify/assert"
10
11
)
11
12
@@ -18,7 +19,9 @@ func TestGetConfigPathFromXDG_CONFIG_HOME(t *testing.T) {
18
19
os .Setenv ("XDG_CONFIG_HOME" , "./testdata/fromxdghome" )
19
20
defer os .Unsetenv ("XDG_CONFIG_HOME" )
20
21
configPath := GetConfigPath ()
22
+
21
23
assert .Equal (t , "testdata/fromxdghome/ArduinoCreateAgent/config.ini" , configPath .String ())
24
+ checkIniName (t , configPath , "this-is-a-config-file-from-xdghome-dir" )
22
25
}
23
26
24
27
// 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) {
29
32
os .Setenv ("HOME" , "./testdata/fromhome" )
30
33
defer os .Unsetenv ("HOME" )
31
34
configPath := GetConfigPath ()
32
- assert .Equal (t , "testdata/fromhome/.config/ArduinoCreateAgent/config.ini" , configPath .String ())
33
35
36
+ assert .Equal (t , "testdata/fromhome/.config/ArduinoCreateAgent/config.ini" , configPath .String ())
37
+ checkIniName (t , configPath , "this-is-a-config-file-from-home-di" )
34
38
}
35
39
36
40
// 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) {
46
50
47
51
configPath := GetConfigPath ()
48
52
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" )
50
54
}
51
55
52
56
// 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) {
70
74
configPath := GetConfigPath ()
71
75
72
76
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)
73
78
74
79
givenContent , err := paths .New (configPath .String ()).ReadFile ()
75
80
if err != nil {
@@ -79,3 +84,15 @@ func TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied(t *testing.T) {
79
84
assert .Equal (t , string (configContent ), string (givenContent ))
80
85
81
86
}
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
+ }
0 commit comments