Skip to content

Commit 5f1c835

Browse files
committed
fic nil options
1 parent 2d88d4b commit 5f1c835

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

go/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ func NewClient(options *ClientOptions) *Client {
144144
if options.LogLevel != "" {
145145
opts.LogLevel = options.LogLevel
146146
}
147-
if options.Env == nil {
148-
opts.Env = os.Environ()
149-
} else {
147+
if options.Env != nil {
150148
opts.Env = options.Env
151149
}
152150
if options.AutoStart != nil {
@@ -163,6 +161,11 @@ func NewClient(options *ClientOptions) *Client {
163161
}
164162
}
165163

164+
// Default Env to current environment if not set
165+
if opts.Env == nil {
166+
opts.Env = os.Environ()
167+
}
168+
166169
// Check environment variable for CLI path
167170
if cliPath := os.Getenv("COPILOT_CLI_PATH"); cliPath != "" {
168171
opts.CLIPath = cliPath

go/client_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ func TestClient_EnvOptions(t *testing.T) {
340340
}
341341
})
342342

343+
t.Run("should default to inherit from current process with nil options", func(t *testing.T) {
344+
client := NewClient(nil)
345+
346+
if want := os.Environ(); !reflect.DeepEqual(client.options.Env, want) {
347+
t.Errorf("Expected Env to be %v, got %v", want, client.options.Env)
348+
}
349+
})
350+
343351
t.Run("should allow empty environment", func(t *testing.T) {
344352
client := NewClient(&ClientOptions{
345353
Env: []string{},

0 commit comments

Comments
 (0)