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+ }
0 commit comments