|
5 | 5 | "context" |
6 | 6 | "errors" |
7 | 7 | "io" |
| 8 | + "strings" |
8 | 9 | "testing" |
9 | 10 |
|
10 | 11 | "github.com/localstack/lstk/internal/log" |
@@ -65,3 +66,25 @@ func TestServicePortRange_ReturnsExpectedPorts(t *testing.T) { |
65 | 66 | assert.Equal(t, "4559", ports[50].HostPort) |
66 | 67 | } |
67 | 68 |
|
| 69 | +func TestFilterHostEnv(t *testing.T) { |
| 70 | + tests := []struct { |
| 71 | + name string |
| 72 | + env string |
| 73 | + expected bool |
| 74 | + }{ |
| 75 | + {"CI is included", "CI=true", true}, |
| 76 | + {"LOCALSTACK_DISABLE_EVENTS is included", "LOCALSTACK_DISABLE_EVENTS=1", true}, |
| 77 | + {"LOCALSTACK_HOST is included", "LOCALSTACK_HOST=0.0.0.0", true}, |
| 78 | + {"LOCALSTACK_AUTH_TOKEN is excluded", "LOCALSTACK_AUTH_TOKEN=secret", false}, |
| 79 | + {"PATH is excluded", "PATH=/usr/bin", false}, |
| 80 | + {"HOME is excluded", "HOME=/root", false}, |
| 81 | + {"LOCALSTACK_BUILD_VERSION is included", "LOCALSTACK_BUILD_VERSION=3.0.0", true}, |
| 82 | + } |
| 83 | + |
| 84 | + for _, tt := range tests { |
| 85 | + t.Run(tt.name, func(t *testing.T) { |
| 86 | + got := strings.HasPrefix(tt.env, "CI=") || (strings.HasPrefix(tt.env, "LOCALSTACK_") && !strings.HasPrefix(tt.env, "LOCALSTACK_AUTH_TOKEN=")) |
| 87 | + assert.Equal(t, tt.expected, got) |
| 88 | + }) |
| 89 | + } |
| 90 | +} |
0 commit comments