on main help sign in
test: fix local test suite, ignore machine environ (#1605)
f32733cAndrey Nering
internal/config/load.go+2−1
@@ -14,6 +14,7 @@ import (
14 "slices"
14 "slices"
15 "strconv"
15 "strconv"
16 "strings"
16 "strings"
17+ "testing"
17
18
18 "github.com/charmbracelet/catwalk/pkg/catwalk"
19 "github.com/charmbracelet/catwalk/pkg/catwalk"
19 "github.com/charmbracelet/crush/internal/csync"
20 "github.com/charmbracelet/crush/internal/csync"
@@ -672,7 +673,7 @@ func hasAWSCredentials(env env.Env) bool {
672 return true
673 return true
673 }
674 }
674
675
675− if _, err := os.Stat(filepath.Join(home.Dir(), ".aws/credentials")); err == nil {
676+ if _, err := os.Stat(filepath.Join(home.Dir(), ".aws/credentials")); err == nil && !testing.Testing() {
676 return true
677 return true
677 }
678 }
678
679
internal/env/env.go+7−1
@@ -1,6 +1,9 @@
1package env
1package env
2
2
3−import "os"
3+import (
4+ "os"
5+ "testing"
6+)
4
7
5type Env interface {
8type Env interface {
6 Get(key string) string
9 Get(key string) string
@@ -23,6 +26,9 @@ func (o *osEnv) Env() []string {
23}
26}
24
27
25func New() Env {
28func New() Env {
29+ if testing.Testing() {
30+ return NewFromMap(nil)
31+ }
26 return &osEnv{}
32 return &osEnv{}
27}
33}
28
34
internal/env/env_test.go+2−2
@@ -8,7 +8,7 @@ import (
8)
8)
9
9
10func TestOsEnv_Get(t *testing.T) {
10func TestOsEnv_Get(t *testing.T) {
11− env := New()
11+ env := &osEnv{}
12
12
13 // Test getting an existing environment variable
13 // Test getting an existing environment variable
14 t.Setenv("TEST_VAR", "test_value")
14 t.Setenv("TEST_VAR", "test_value")
@@ -22,7 +22,7 @@ func TestOsEnv_Get(t *testing.T) {
22}
22}
23
23
24func TestOsEnv_Env(t *testing.T) {
24func TestOsEnv_Env(t *testing.T) {
25− env := New()
25+ env := &osEnv{}
26
26
27 envVars := env.Env()
27 envVars := env.Env()
28
28