github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/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  		tt := tt
    28  		t.Run(tt.name, func(t *testing.T) {
    29  			assert.ElementsMatch(t, tt.expected, PrepareEnv(Get(ctx), tt.env))
    30  		})
    31  	}
    32  }
    33  
    34  func TestPrepareEnvWithColor(t *testing.T) {
    35  	out := &bytes.Buffer{}
    36  	logger := NewFuncLogger(true, DebugLvl, func(level Level, fields Fields, bytes []byte) error {
    37  		_, err := out.Write(bytes)
    38  		return err
    39  	})
    40  	ctx := WithLogger(context.Background(), logger)
    41  	assert.ElementsMatch(t, []string{
    42  		"FORCE_COLOR=1",
    43  		"LINES=24",
    44  		"COLUMNS=80",
    45  		"PYTHONUNBUFFERED=1",
    46  	}, PrepareEnv(Get(ctx), nil))
    47  }