Skip to content

Commit 5ea7307

Browse files
committed
Inline host env filtering, remove unnecessary abstraction
1 parent e15ade5 commit 5ea7307

2 files changed

Lines changed: 6 additions & 69 deletions

File tree

internal/container/start.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ func Start(ctx context.Context, rt runtime.Runtime, sink output.Sink, opts Start
9696

9797
tel := opts.Telemetry
9898

99-
hostEnv := collectHostEnv()
99+
var hostEnv []string
100+
for _, e := range os.Environ() {
101+
if strings.HasPrefix(e, "CI=") || (strings.HasPrefix(e, "LOCALSTACK_") && !strings.HasPrefix(e, "LOCALSTACK_AUTH_TOKEN=")) {
102+
hostEnv = append(hostEnv, e)
103+
}
104+
}
100105

101106
containers := make([]runtime.ContainerConfig, len(opts.Containers))
102107
for i, c := range opts.Containers {
@@ -230,16 +235,6 @@ func emitPostStartPointers(sink output.Sink, resolvedHost, webAppURL string) {
230235
output.EmitSecondary(sink, tips[rand.IntN(len(tips))])
231236
}
232237

233-
func collectHostEnv() []string {
234-
var env []string
235-
for _, e := range os.Environ() {
236-
if strings.HasPrefix(e, "CI=") || (strings.HasPrefix(e, "LOCALSTACK_") && !strings.HasPrefix(e, "LOCALSTACK_AUTH_TOKEN=")) {
237-
env = append(env, e)
238-
}
239-
}
240-
return env
241-
}
242-
243238
func pullImages(ctx context.Context, rt runtime.Runtime, sink output.Sink, tel *telemetry.Client, containers []runtime.ContainerConfig) (map[string]bool, error) {
244239
pulled := make(map[string]bool, len(containers))
245240
for _, c := range containers {

internal/container/start_test.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"context"
66
"errors"
77
"io"
8-
"os"
9-
"strings"
108
"testing"
119

1210
"github.com/localstack/lstk/internal/log"
@@ -67,59 +65,3 @@ func TestServicePortRange_ReturnsExpectedPorts(t *testing.T) {
6765
assert.Equal(t, "4559", ports[50].HostPort)
6866
}
6967

70-
func TestCollectHostEnv_ForwardsCIVariable(t *testing.T) {
71-
tests := []struct {
72-
name string
73-
setup func(t *testing.T)
74-
wantCI bool
75-
ciValue string
76-
}{
77-
{
78-
name: "CI=true",
79-
setup: func(t *testing.T) { t.Setenv("CI", "true") },
80-
wantCI: true,
81-
ciValue: "true",
82-
},
83-
{
84-
name: "CI=1",
85-
setup: func(t *testing.T) { t.Setenv("CI", "1") },
86-
wantCI: true,
87-
ciValue: "1",
88-
},
89-
{
90-
name: "CI=false",
91-
setup: func(t *testing.T) { t.Setenv("CI", "false") },
92-
wantCI: true,
93-
ciValue: "false",
94-
},
95-
{
96-
name: "CI unset",
97-
setup: func(t *testing.T) {
98-
original, wasSet := os.LookupEnv("CI")
99-
require.NoError(t, os.Unsetenv("CI"))
100-
t.Cleanup(func() {
101-
if wasSet {
102-
require.NoError(t, os.Setenv("CI", original))
103-
}
104-
})
105-
},
106-
wantCI: false,
107-
},
108-
}
109-
110-
for _, tt := range tests {
111-
t.Run(tt.name, func(t *testing.T) {
112-
tt.setup(t)
113-
114-
env := collectHostEnv()
115-
116-
if tt.wantCI {
117-
assert.Contains(t, env, "CI="+tt.ciValue, "CI environment variable should be forwarded")
118-
} else {
119-
for _, e := range env {
120-
assert.False(t, strings.HasPrefix(e, "CI="), "CI should not be forwarded when unset")
121-
}
122-
}
123-
})
124-
}
125-
}

0 commit comments

Comments
 (0)