mirror of
https://github.com/tw93/Mole.git
synced 2026-03-23 02:00:08 +00:00
Improve update checks and cleanup UX, add timeout regressions
This commit is contained in:
44
cmd/status/main_test.go
Normal file
44
cmd/status/main_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestShouldUseJSONOutput_ForceFlag(t *testing.T) {
|
||||
if !shouldUseJSONOutput(true, nil) {
|
||||
t.Fatalf("expected force JSON flag to enable JSON mode")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldUseJSONOutput_NilStdout(t *testing.T) {
|
||||
if shouldUseJSONOutput(false, nil) {
|
||||
t.Fatalf("expected nil stdout to keep TUI mode")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldUseJSONOutput_NonTTYPipe(t *testing.T) {
|
||||
reader, writer, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Fatalf("create pipe: %v", err)
|
||||
}
|
||||
defer reader.Close()
|
||||
defer writer.Close()
|
||||
|
||||
if !shouldUseJSONOutput(false, writer) {
|
||||
t.Fatalf("expected pipe stdout to use JSON mode")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldUseJSONOutput_NonTTYFile(t *testing.T) {
|
||||
tmpFile, err := os.CreateTemp("", "mole-status-stdout-*.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("create temp file: %v", err)
|
||||
}
|
||||
defer os.Remove(tmpFile.Name())
|
||||
defer tmpFile.Close()
|
||||
|
||||
if !shouldUseJSONOutput(false, tmpFile) {
|
||||
t.Fatalf("expected file stdout to use JSON mode")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user