paker: tests for ColoredUi not showing color with env vars

This commit is contained in:
Mitchell Hashimoto 2013-12-16 20:48:39 -08:00
parent 69f971094c
commit ecf211ceed
1 changed files with 29 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package packer
import (
"bytes"
"os"
"strings"
"testing"
)
@ -36,6 +37,34 @@ func TestColoredUi(t *testing.T) {
}
}
func TestColoredUi_noColorEnv(t *testing.T) {
bufferUi := testUi()
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi}
// Set the env var to get rid of the color
oldenv := os.Getenv("PACKER_NO_COLOR")
os.Setenv("PACKER_NO_COLOR", "1")
defer os.Setenv("PACKER_NO_COLOR", oldenv)
ui.Say("foo")
result := readWriter(bufferUi)
if result != "foo\n" {
t.Fatalf("invalid output: %s", result)
}
ui.Message("foo")
result = readWriter(bufferUi)
if result != "foo\n" {
t.Fatalf("invalid output: %s", result)
}
ui.Error("foo")
result = readWriter(bufferUi)
if result != "foo\n" {
t.Fatalf("invalid output: %s", result)
}
}
func TestTargettedUi(t *testing.T) {
bufferUi := testUi()
targettedUi := &TargettedUi{