Skip to content

Commit

Permalink
feat(config): skip tests if not linux
Browse files Browse the repository at this point in the history
dido18 committed Jan 29, 2025
1 parent 29a1bf3 commit 9143b02
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -143,6 +143,7 @@ func SetInstallCertsIni(filename string, value string) error {
return nil
}

// GetConfigPath returns the path to the config file
func GetConfigPath() *paths.Path {
// Let's handle the config
configDir := GetDefaultConfigDir()
20 changes: 19 additions & 1 deletion config/config_test.go → config/config_linux_test.go
Original file line number Diff line number Diff line change
@@ -2,30 +2,42 @@ package config

import (
"os"
"runtime"
"testing"

"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/assert"
)

// TestGetConfigPathFromXDG_CONFIG_HOME tests the case when the config.ini is read from XDG_CONFIG_HOME/ArduinoCreateAgent/config.ini
func TestGetConfigPathFromXDG_CONFIG_HOME(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Skipping test on non-linux OS")
}
// read config from $XDG_CONFIG_HOME/ArduinoCreateAgent/config.ini
os.Setenv("XDG_CONFIG_HOME", "./testdata/fromxdghome")
defer os.Unsetenv("XDG_CONFIG_HOME")
configPath := GetConfigPath()
assert.Equal(t, "testdata/fromxdghome/ArduinoCreateAgent/config.ini", configPath.String())
}

// TestGetConfigPathFromHOME tests the case when the config.ini is read from $HOME/.config/ArduinoCreateAgent/config.ini
func TestGetConfigPathFromHOME(t *testing.T) {
// Test case 2: read config from $HOME/.config/ArduinoCreateAgent/config.ini "
if runtime.GOOS != "linux" {
t.Skip("Skipping test on non-linux OS")
}
os.Setenv("HOME", "./testdata/fromhome")
defer os.Unsetenv("HOME")
configPath := GetConfigPath()
assert.Equal(t, "testdata/fromhome/.config/ArduinoCreateAgent/config.ini", configPath.String())

}

// TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG tests the case when the config.ini is read from ARDUINO_CREATE_AGENT_CONFIG env variable
func TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Skipping test on non-linux OS")
}
// $HOME must be always set, otherwise panic
os.Setenv("HOME", "./testdata/dummyhome")

@@ -34,11 +46,17 @@ func TestGetConfigPathFromARDUINO_CREATE_AGENT_CONFIG(t *testing.T) {

configPath := GetConfigPath()
assert.Equal(t, "./testdata/from-arduino-create-agent-config-env/config.ini", configPath.String())

}

// TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied tests the case when the default config.ini is copied into $HOME/.config/ArduinoCreateAgent/config.ini
// from the default config.ini
// If the ARDUINO_CREATE_AGENT_CONFIG is NOT set and the config.ini does not exist in HOME directory
// then it copies the default config (the config.ini) into the HOME directory
func TestIfHomeDoesNotContainConfigTheDefaultConfigAreCopied(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Skipping test on non-linux OS")
}
// $HOME must be always set, otherwise panic
os.Setenv("HOME", "./testdata/home-without-config")

0 comments on commit 9143b02

Please sign in to comment.