github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/lifecycle/build/command_test.go (about) 1 package build 2 3 import ( 4 "os" 5 "testing" 6 ) 7 8 func TestSetEnv(t *testing.T) { 9 b := &Command{} 10 11 t.Run("Unset", func(t *testing.T) { 12 err := b.setenv() 13 if err != nil { 14 t.Errorf("err should be nil, got %v", err) 15 } 16 17 env := os.Getenv("GO_ENV") 18 if env != "production" { 19 t.Errorf("GO_ENV should have been production, got %v", env) 20 } 21 }) 22 23 t.Run("Set to development", func(t *testing.T) { 24 err := os.Setenv("GO_ENV", "development") 25 if err != nil { 26 t.Errorf("err should be nil, got %v", err) 27 } 28 29 err = b.setenv() 30 if err != nil { 31 t.Errorf("err should be nil, got %v", err) 32 } 33 34 env := os.Getenv("GO_ENV") 35 if env != "development" { 36 t.Errorf("GO_ENV should have been %v, got %v", "development", env) 37 } 38 39 }) 40 }