github.com/tilt-dev/tilt@v0.36.0/pkg/logger/env_test.go (about) 1 package logger 2 3 import ( 4 "bytes" 5 "context" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestPrepareEnv(t *testing.T) { 12 out := &bytes.Buffer{} 13 ctx := WithLogger(context.Background(), NewTestLogger(out)) 14 15 tests := []struct { 16 name string 17 env []string 18 expected []string 19 }{ 20 {"defaults-nil", nil, []string{"LINES=24", "COLUMNS=80", "PYTHONUNBUFFERED=1"}}, 21 {"defaults", []string{}, []string{"LINES=24", "COLUMNS=80", "PYTHONUNBUFFERED=1"}}, 22 {"python-unbuffered", []string{"PYTHONUNBUFFERED=2"}, []string{"LINES=24", "COLUMNS=80", "PYTHONUNBUFFERED=2"}}, 23 {"wide-columns", []string{"COLUMNS=200"}, []string{"LINES=24", "COLUMNS=200", "PYTHONUNBUFFERED=1"}}, 24 {"so-many-lines", []string{"LINES=20000"}, []string{"LINES=20000", "COLUMNS=80", "PYTHONUNBUFFERED=1"}}, 25 } 26 for _, tt := range tests { 27 t.Run(tt.name, func(t *testing.T) { 28 assert.ElementsMatch(t, tt.expected, PrepareEnv(Get(ctx), tt.env)) 29 }) 30 } 31 } 32 33 func TestPrepareEnvWithColor(t *testing.T) { 34 out := &bytes.Buffer{} 35 logger := NewFuncLogger(true, DebugLvl, func(level Level, fields Fields, bytes []byte) error { 36 _, err := out.Write(bytes) 37 return err 38 }) 39 ctx := WithLogger(context.Background(), logger) 40 assert.ElementsMatch(t, []string{ 41 "FORCE_COLOR=1", 42 "LINES=24", 43 "COLUMNS=80", 44 "PYTHONUNBUFFERED=1", 45 }, PrepareEnv(Get(ctx), nil)) 46 }