diff --git a/internal/config/load.go b/internal/config/load.go index 8f3ad171d2ae2e196584223e55d24d42b200e073..14dd0f8792bcbabaa865efe47e0db5e721cf3827 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -14,6 +14,7 @@ import ( "slices" "strconv" "strings" + "testing" "github.com/charmbracelet/catwalk/pkg/catwalk" "github.com/charmbracelet/crush/internal/csync" @@ -672,7 +673,7 @@ func hasAWSCredentials(env env.Env) bool { return true } - if _, err := os.Stat(filepath.Join(home.Dir(), ".aws/credentials")); err == nil { + if _, err := os.Stat(filepath.Join(home.Dir(), ".aws/credentials")); err == nil && !testing.Testing() { return true } diff --git a/internal/env/env.go b/internal/env/env.go index 24d44d10fca5a374732283d0aca4ddc8166b879b..fa7546f8ebd28ed0c44528f7d9b8ae4b03db8b89 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -1,6 +1,9 @@ package env -import "os" +import ( + "os" + "testing" +) type Env interface { Get(key string) string @@ -23,6 +26,9 @@ func (o *osEnv) Env() []string { } func New() Env { + if testing.Testing() { + return NewFromMap(nil) + } return &osEnv{} } diff --git a/internal/env/env_test.go b/internal/env/env_test.go index 6bd323e0cb169c2fd06397ed7b015de98145b105..a86b8f4140a57d564797f260b24262472c9ad058 100644 --- a/internal/env/env_test.go +++ b/internal/env/env_test.go @@ -8,7 +8,7 @@ import ( ) func TestOsEnv_Get(t *testing.T) { - env := New() + env := &osEnv{} // Test getting an existing environment variable t.Setenv("TEST_VAR", "test_value") @@ -22,7 +22,7 @@ func TestOsEnv_Get(t *testing.T) { } func TestOsEnv_Env(t *testing.T) { - env := New() + env := &osEnv{} envVars := env.Env()