@@ -3,6 +3,7 @@ package copilot
33import (
44 "os"
55 "path/filepath"
6+ "reflect"
67 "regexp"
78 "testing"
89)
@@ -334,6 +335,53 @@ func TestClient_AuthOptions(t *testing.T) {
334335 })
335336}
336337
338+ func TestClient_EnvOptions (t * testing.T ) {
339+ t .Run ("should store custom environment variables" , func (t * testing.T ) {
340+ client := NewClient (& ClientOptions {
341+ Env : []string {"FOO=bar" , "BAZ=qux" },
342+ })
343+
344+ if len (client .options .Env ) != 2 {
345+ t .Errorf ("Expected 2 environment variables, got %d" , len (client .options .Env ))
346+ }
347+ if client .options .Env [0 ] != "FOO=bar" {
348+ t .Errorf ("Expected first env var to be 'FOO=bar', got %q" , client .options .Env [0 ])
349+ }
350+ if client .options .Env [1 ] != "BAZ=qux" {
351+ t .Errorf ("Expected second env var to be 'BAZ=qux', got %q" , client .options .Env [1 ])
352+ }
353+ })
354+
355+ t .Run ("should default to inherit from current process" , func (t * testing.T ) {
356+ client := NewClient (& ClientOptions {})
357+
358+ if want := os .Environ (); ! reflect .DeepEqual (client .options .Env , want ) {
359+ t .Errorf ("Expected Env to be %v, got %v" , want , client .options .Env )
360+ }
361+ })
362+
363+ t .Run ("should default to inherit from current process with nil options" , func (t * testing.T ) {
364+ client := NewClient (nil )
365+
366+ if want := os .Environ (); ! reflect .DeepEqual (client .options .Env , want ) {
367+ t .Errorf ("Expected Env to be %v, got %v" , want , client .options .Env )
368+ }
369+ })
370+
371+ t .Run ("should allow empty environment" , func (t * testing.T ) {
372+ client := NewClient (& ClientOptions {
373+ Env : []string {},
374+ })
375+
376+ if client .options .Env == nil {
377+ t .Error ("Expected Env to be non-nil empty slice" )
378+ }
379+ if len (client .options .Env ) != 0 {
380+ t .Errorf ("Expected 0 environment variables, got %d" , len (client .options .Env ))
381+ }
382+ })
383+ }
384+
337385func findCLIPathForTest () string {
338386 abs , _ := filepath .Abs ("../nodejs/node_modules/@github/copilot/index.js" )
339387 if fileExistsForTest (abs ) {
0 commit comments