From ecf211ceed938b3156f4db4858a939733fa5ed56 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 16 Dec 2013 20:48:39 -0800 Subject: [PATCH] paker: tests for ColoredUi not showing color with env vars --- packer/ui_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packer/ui_test.go b/packer/ui_test.go index c411eb0e5..d512d8d13 100644 --- a/packer/ui_test.go +++ b/packer/ui_test.go @@ -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{