Files
Crussell/backend/internal/logutil/logutil_test.go
T
popertots 3029fd5179
CI / Nginx config check (push) Successful in 13s
CI / Env docs check (push) Successful in 15s
CI / Docker compose check (push) Successful in 15s
CI / Frontend major deps (push) Failing after 24s
CI / Frontend deps check (push) Successful in 30s
CI / Secrets scan (push) Successful in 38s
CI / Go build (push) Successful in 39s
CI / Frontend build (push) Successful in 1m3s
CI / Knip (push) Successful in 45s
CI / Go vet (prod) (push) Failing after 1m42s
CI / Frontend a11y check (push) Successful in 2m34s
CI / Go vet (dev) (push) Successful in 2m29s
CI / Staticcheck (prod) (push) Failing after 2m38s
CI / go mod tidy (push) Successful in 1m3s
CI / Staticcheck (dev) (push) Successful in 2m55s
CI / Frontend QC (audit) (push) Successful in 51s
CI / golangci-lint (push) Successful in 3m22s
CI / Go vulnerabilities (push) Successful in 1m26s
CI / Frontend QC (typecheck) (push) Successful in 2m18s
CI / Security scan (prod) (push) Successful in 4m18s
CI / Security scan (dev) (push) Successful in 4m40s
CI / Tests (prod) (push) Has been skipped
CI / Tests (dev) (push) Has been skipped
CI / Race (prod) (push) Has been skipped
CI / Race (dev) (push) Has been skipped
CI / Frontend QC (lint) (push) Successful in 2m18s
CI / Svelte strict check (push) Successful in 43s
test: add coverage tests across backend + fix mock for PENDING checkout support
New test files cover previously untested paths across DAV, validators,
S3, Square, mw, bookings, user, and payments packages.

Includes mock fix: HoldCheckouts flag on MockClient allows tests to
pause auto-complete goroutine for testing PENDING checkout states.

Coverage: 50.4% → 65.0% (+14.6pp)
2026-07-10 18:13:44 +01:00

198 lines
3.7 KiB
Go

//go:build test
package logutil
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// NO_COLOR is unset in tests so all ANSI vars are non-empty. The
// noColor=true path is not testable here because init() runs once at
// package load time; it would require a separate test binary.
func TestColorVars_AreNotEmpty(t *testing.T) {
t.Parallel()
tests := []struct {
name string
v string
}{
{"Reset", Reset},
{"Bold", Bold},
{"Dim", Dim},
{"Cyan", Cyan},
{"Green", Green},
{"Red", Red},
{"Yellow", Yellow},
{"Magenta", Magenta},
{"BoldGreen", BoldGreen},
{"BoldYellow", BoldYellow},
{"BoldRed", BoldRed},
{"BoldBlue", BoldBlue},
{"BoldMagenta", BoldMagenta},
{"DebugLvl", DebugLvl},
{"WarnLvl", WarnLvl},
{"ErrorLvl", ErrorLvl},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
assert.NotEmpty(t, tt.v, "package var %s should contain ANSI code when NO_COLOR is unset", tt.name)
})
}
}
func TestColorVars_StartWithEscape(t *testing.T) {
t.Parallel()
tests := []struct {
name string
v string
}{
{"Reset", Reset},
{"Bold", Bold},
{"Dim", Dim},
{"Cyan", Cyan},
{"Green", Green},
{"Red", Red},
{"Yellow", Yellow},
{"Magenta", Magenta},
{"BoldGreen", BoldGreen},
{"BoldYellow", BoldYellow},
{"BoldRed", BoldRed},
{"BoldBlue", BoldBlue},
{"BoldMagenta", BoldMagenta},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
assert.True(t, tt.v[0] == '\033', "package var %s should start with ESC byte", tt.name)
})
}
}
func TestColoredDuration(t *testing.T) {
t.Parallel()
tests := []struct {
name string
d time.Duration
wantPre string
wantText string
wantSuf string
}{
{
name: "under_500ms_returns_green",
d: 200 * time.Millisecond,
wantPre: Green,
wantText: "200ms",
wantSuf: Reset,
},
{
name: "exactly_499ms_returns_green",
d: 499 * time.Millisecond,
wantPre: Green,
wantText: "499ms",
wantSuf: Reset,
},
{
name: "exactly_500ms_returns_yellow",
d: 500 * time.Millisecond,
wantPre: Yellow,
wantText: "500ms",
wantSuf: Reset,
},
{
name: "between_500ms_and_5s_returns_yellow",
d: 3 * time.Second,
wantPre: Yellow,
wantText: "3s",
wantSuf: Reset,
},
{
name: "exactly_4999ms_returns_yellow",
d: 4999 * time.Millisecond,
wantPre: Yellow,
wantText: "4.999s",
wantSuf: Reset,
},
{
name: "exactly_5s_returns_red",
d: 5 * time.Second,
wantPre: Red,
wantText: "5s",
wantSuf: Reset,
},
{
name: "over_5s_returns_red",
d: 10 * time.Second,
wantPre: Red,
wantText: "10s",
wantSuf: Reset,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := ColoredDuration(tt.d)
want := tt.wantPre + tt.wantText + tt.wantSuf
assert.Equal(t, want, got)
})
}
}
func TestColoredRows(t *testing.T) {
t.Parallel()
tests := []struct {
name string
n int
wantPre string
wantText string
wantSuf string
}{
{
name: "zero_rows_plural",
n: 0,
wantPre: BoldBlue,
wantText: "0 rows",
wantSuf: Reset,
},
{
name: "one_row_singular",
n: 1,
wantPre: BoldBlue,
wantText: "1 row",
wantSuf: Reset,
},
{
name: "two_rows_plural",
n: 2,
wantPre: BoldBlue,
wantText: "2 rows",
wantSuf: Reset,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := ColoredRows(tt.n)
want := tt.wantPre + tt.wantText + tt.wantSuf
assert.Equal(t, want, got)
})
}
}