Skip to content

Commit 139ffb4

Browse files
committed
added test for no color
1 parent 5bf115e commit 139ffb4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cmd/root_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"os"
6+
"strings"
7+
"testing"
8+
9+
log "github.com/charmbracelet/log"
10+
)
11+
12+
func TestNoColorLog(t *testing.T) {
13+
// Set the environment variable to disable color
14+
// t.Setenv("NO_COLOR", "1")
15+
t.Setenv("ATMOS_LOGS_LEVEL", "Debug")
16+
t.Setenv("NO_COLOR", "1")
17+
// Create a buffer to capture the output
18+
var buf bytes.Buffer
19+
log.SetOutput(&buf)
20+
21+
oldArgs := os.Args
22+
defer func() {
23+
os.Args = oldArgs
24+
}()
25+
// Set the arguments for the command
26+
os.Args = []string{"atmos", "about"}
27+
// Execute the command
28+
if err := Execute(); err != nil {
29+
t.Fatalf("Failed to execute command: %v", err)
30+
}
31+
// Check if the output is without color
32+
output := buf.String()
33+
if strings.Contains(output, "\033[") {
34+
t.Errorf("Expected no color in output, but got: %s", output)
35+
}
36+
t.Log(output, "output")
37+
}

0 commit comments

Comments
 (0)