diff --git a/config/toml_test.go b/config/toml_test.go index 2b222f1e8..16bd849d1 100644 --- a/config/toml_test.go +++ b/config/toml_test.go @@ -10,11 +10,13 @@ import ( func TestFindentrypoint(t *testing.T) { t.Run("finds entrypoint in current directory", func(t *testing.T) { - dir := t.TempDir() + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + require.NoError(t, os.Chdir(dir)) entrypointPath := filepath.Join(dir, "main.go") - err := os.WriteFile(entrypointPath, []byte{}, 0600) + err = os.WriteFile(entrypointPath, []byte{}, 0600) require.NoError(t, err) dirName, fullDirPath := FindEntrypoint() @@ -23,7 +25,9 @@ func TestFindentrypoint(t *testing.T) { }) t.Run("returns error if entrypoint not found", func(t *testing.T) { - dir := t.TempDir() + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + require.NoError(t, os.Chdir(dir)) dirName, fullDirPath := FindEntrypoint() @@ -32,10 +36,11 @@ func TestFindentrypoint(t *testing.T) { }) t.Run("finds entrypoint in subdirectory", func(t *testing.T) { - parentDir := t.TempDir() + parentDir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) dir := filepath.Join(parentDir, "child") - err := os.Mkdir(dir, 0750) + err = os.Mkdir(dir, 0750) require.NoError(t, err) require.NoError(t, os.Chdir(dir)) @@ -52,9 +57,11 @@ func TestFindentrypoint(t *testing.T) { func TestFindConfigFile(t *testing.T) { t.Run("finds config file in current directory", func(t *testing.T) { - dir := t.TempDir() + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + configPath := filepath.Join(dir, RollkitToml) - err := os.WriteFile(configPath, []byte{}, 0600) + err = os.WriteFile(configPath, []byte{}, 0600) require.NoError(t, err) foundPath, err := findConfigFile(dir) @@ -63,9 +70,11 @@ func TestFindConfigFile(t *testing.T) { }) t.Run("finds config file in parent directory", func(t *testing.T) { - parentDir := t.TempDir() + parentDir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + dir := filepath.Join(parentDir, "child") - err := os.Mkdir(dir, 0750) + err = os.Mkdir(dir, 0750) require.NoError(t, err) configPath := filepath.Join(parentDir, RollkitToml) @@ -78,16 +87,21 @@ func TestFindConfigFile(t *testing.T) { }) t.Run("returns error if config file not found", func(t *testing.T) { - _, err := findConfigFile(t.TempDir()) + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + + _, err = findConfigFile(dir) require.Error(t, err) }) } func TestReadToml(t *testing.T) { t.Run("reads TOML configuration from file", func(t *testing.T) { - dir := t.TempDir() + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + configPath := filepath.Join(dir, RollkitToml) - err := os.WriteFile(configPath, []byte(` + err = os.WriteFile(configPath, []byte(` entrypoint = "./cmd/gm/main.go" [chain] @@ -108,17 +122,21 @@ config_dir = "config" }) t.Run("returns error if config file not found", func(t *testing.T) { - dir := t.TempDir() + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + require.NoError(t, os.Chdir(dir)) - _, err := ReadToml() + _, err = ReadToml() require.Error(t, err) }) t.Run("sets RootDir even if empty toml", func(t *testing.T) { - dir := t.TempDir() + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + configPath := filepath.Join(dir, RollkitToml) - err := os.WriteFile(configPath, []byte{}, 0600) + err = os.WriteFile(configPath, []byte{}, 0600) require.NoError(t, err) require.NoError(t, os.Chdir(dir)) @@ -130,14 +148,16 @@ config_dir = "config" }) t.Run("returns error if config file cannot be decoded", func(t *testing.T) { - dir := t.TempDir() + dir, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + configPath := filepath.Join(dir, RollkitToml) require.NoError(t, os.WriteFile(configPath, []byte(` blablabla `), 0600)) require.NoError(t, os.Chdir(dir)) - _, err := ReadToml() + _, err = ReadToml() require.Error(t, err) }) }