fix(diary): skip HideOnTTY records only on a terminal console, also with forced color (IN-01, quick-261028-rqd)
This commit is contained in:
36
modules/diary/console_internal_test.go
Normal file
36
modules/diary/console_internal_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package diary
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/colorprofile"
|
||||
)
|
||||
|
||||
// TestConsoleHideOnTTYTerminal (IN-01): the styled console handler skips a
|
||||
// HideOnTTY record when its writer is a terminal, and writes ordinary
|
||||
// records.
|
||||
func TestConsoleHideOnTTYTerminal(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
h := newConsoleHandler(&buf, ConsoleOptions{Profile: colorprofile.ANSI}, new(atomic.Bool))
|
||||
h.terminal = true
|
||||
hidden := slog.NewRecord(time.Time{}, slog.LevelInfo, "hidden summary", 0)
|
||||
if err := h.Handle(HideOnTTY(context.Background()), hidden); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
shown := slog.NewRecord(time.Time{}, slog.LevelInfo, "shown line", 0)
|
||||
if err := h.Handle(context.Background(), shown); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(buf.String(), "hidden summary") {
|
||||
t.Errorf("terminal console shows a HideOnTTY record:\n%s", buf.String())
|
||||
}
|
||||
if !strings.Contains(buf.String(), "shown line") {
|
||||
t.Errorf("terminal console lacks the ordinary record:\n%s", buf.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user