From b06fcbf502c5690ec9345cc1e13169d25bcda87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Sun, 13 Nov 2022 11:13:42 +0100 Subject: [PATCH] Add Test_noColorIsSet --- color_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/color_test.go b/color_test.go index 81255b6..e22cb78 100644 --- a/color_test.go +++ b/color_test.go @@ -199,6 +199,41 @@ func TestNoColor_Env(t *testing.T) { } } +func Test_noColorIsSet(t *testing.T) { + tests := []struct { + name string + act func() + want bool + }{ + { + name: "default", + act: func() {}, + want: false, + }, + { + name: "NO_COLOR=1", + act: func() { os.Setenv("NO_COLOR", "1") }, + want: true, + }, + { + name: "NO_COLOR=", + act: func() { os.Setenv("NO_COLOR", "") }, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Cleanup(func() { + os.Unsetenv("NO_COLOR") + }) + tt.act() + if got := noColorIsSet(); got != tt.want { + t.Errorf("noColorIsSet() = %v, want %v", got, tt.want) + } + }) + } +} + func TestColorVisual(t *testing.T) { // First Visual Test Output = colorable.NewColorableStdout()