refactor(diary): share the console types through internal/consolekit so diary no longer links bonfire (IN-07, quick-261028-rqd)

This commit is contained in:
Jakub Zych
2026-10-28 20:46:32 +01:00
parent 3520d5d480
commit f3f87f3cc4
14 changed files with 364 additions and 169 deletions

View File

@@ -0,0 +1,44 @@
package consolekit
import (
"strings"
"testing"
)
// TestPrintAboveHook: without a registered printer PrintAbove reports
// false; with one it forwards the text and its answer; SetPrintAbove(nil)
// removes it again.
func TestPrintAboveHook(t *testing.T) {
t.Cleanup(func() { SetPrintAbove(nil) })
SetPrintAbove(nil)
if PrintAbove("x") {
t.Fatal("PrintAbove without a printer reported true")
}
var got []string
SetPrintAbove(func(s string) bool {
got = append(got, s)
return true
})
if !PrintAbove("line") || strings.Join(got, ",") != "line" {
t.Fatalf("PrintAbove with a printer: got %q", got)
}
SetPrintAbove(nil)
if PrintAbove("again") || len(got) != 1 {
t.Fatalf("PrintAbove after SetPrintAbove(nil): got %q", got)
}
}
// TestNormalizeAndArgs: Normalize caps the verbosity and lets Quiet imply
// NoInteraction; Args emits the flags bonfire forwards.
func TestNormalizeAndArgs(t *testing.T) {
if g := Normalize(Globals{Verbosity: 9, Quiet: true}); g.Verbosity != MaxVerbosity || !g.NoInteraction {
t.Errorf("Normalize = %+v", g)
}
if g := Normalize(Globals{Verbosity: -2}); g.Verbosity != 0 {
t.Errorf("Normalize negative = %+v", g)
}
g := Globals{Verbosity: 2, Quiet: true, NoInteraction: true, Color: ColorNever, Env: "dev"}
if got := strings.Join(g.Args(), " "); got != "-vv -q --no-ansi --env=dev" {
t.Errorf("Args = %q", got)
}
}