@@ -2,30 +2,42 @@ package config
2
2
3
3
import (
4
4
"os"
5
+ "runtime"
5
6
"testing"
6
7
7
8
"github.com/arduino/go-paths-helper"
8
9
"github.com/stretchr/testify/assert"
9
10
)
10
11
12
+ // TestGetConfigPathFromXDG_CONFIG_HOME tests the case when the config.ini is read from XDG_CONFIG_HOME/ArduinoCreateAgent/config.ini
11
13
func TestGetConfigPathFromXDG_CONFIG_HOME (t * testing.T ) {
14
+ if runtime .GOOS != "linux" {
15
+ t .Skip ("Skipping test on non-linux OS" )
16
+ }
12
17
// read config from $XDG_CONFIG_HOME/ArduinoCreateAgent/config.ini
13
18
os .Setenv ("XDG_CONFIG_HOME" , "./testdata/fromxdghome" )
14
19
defer os .Unsetenv ("XDG_CONFIG_HOME" )
15
20
configPath := GetConfigPath ()
16
21
assert .Equal (t , "testdata/fromxdghome/ArduinoCreateAgent/config.ini" , configPath .String ())
17
22
}
18
23
24
+ // TestGetConfigPathFromHOME tests the case when the config.ini is read from $HOME/.config/ArduinoCreateAgent/config.ini
19
25
func TestGetConfigPathFromHOME (t * testing.T ) {
20
- // Test case 2: read config from $HOME/.config/ArduinoCreateAgent/config.ini "
26
+ if runtime .GOOS != "linux" {
27
+ t .Skip ("Skipping test on non-linux OS" )
28
+ }
21
29
os .Setenv ("HOME" , "./testdata/fromhome" )
22
30
defer os .Unsetenv ("HOME" )
23
31
configPath := GetConfigPath ()
24
32
assert .Equal (t , "testdata/fromhome/.config/ArduinoCreateAgent/config.ini" , configPath .String ())
25
33
26
34
}
27
35
36
+ // TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG tests the case when the config.ini is read from ARDUINO_CREATE_AGENT_CONFIG env variable
28
37
func TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG (t * testing.T ) {
38
+ if runtime .GOOS != "linux" {
39
+ t .Skip ("Skipping test on non-linux OS" )
40
+ }
29
41
// $HOME must be always set, otherwise panic
30
42
os .Setenv ("HOME" , "./testdata/dummyhome" )
31
43
@@ -34,11 +46,17 @@ func TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG(t *testing.T) {
34
46
35
47
configPath := GetConfigPath ()
36
48
assert .Equal (t , "./testdata/from-arduino-create-agent-config-env/config.ini" , configPath .String ())
49
+
37
50
}
38
51
52
+ // TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied tests the case when the default config.ini is copied into $HOME/.config/ArduinoCreateAgent/config.ini
53
+ // from the default config.ini
39
54
// If the ARDUINO_CREATE_AGENT_CONFIG is NOT set and the config.ini does not exist in HOME directory
40
55
// then it copies the default config (the config.ini) into the HOME directory
41
56
func TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied (t * testing.T ) {
57
+ if runtime .GOOS != "linux" {
58
+ t .Skip ("Skipping test on non-linux OS" )
59
+ }
42
60
// $HOME must be always set, otherwise panic
43
61
os .Setenv ("HOME" , "./testdata/home-without-config" )
44
62
0 commit comments