diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-22 23:51:18 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-22 23:51:18 +0300 |
| commit | 849951be1d1a7ee9f9302006ccb187bf5b4e36f3 (patch) | |
| tree | 496c924a03a9ea6212e29bb4699e268066ebad81 /internal/io/dlog/dlog_test.go | |
| parent | bf78b3abffee6d49c08ca2980156afc455994969 (diff) | |
feat: DTail fork — server/client feature development
Squashed development of the snonux/dtail fork's product code (internal/, cmd/)
since diverging from mimecast/dtail. Major areas:
- Read/output path: the former "turbo" channel-less path is now the single,
default server-side read/output path for cat/grep/tail and MapReduce; the old
channel-based path and its config/env toggles were removed.
- MapReduce: single aggregate implementation (server + serverless) fed directly
by a processor pipeline, with input-exhausted finalization via the shutdown
coordinator; high-concurrency and data-race fixes.
- Journal source reads (journal:unit.service) via journalctl, Linux-gated behind
a journal-v1 capability.
- Auth-key fast reconnect: in-memory per-user public-key cache with TTL/max-keys,
registered over an authenticated session (AUTHKEY), checked before
authorized_keys.
- Interactive query reload (--interactive-query) with SESSION START/UPDATE
generation boundaries and capability negotiation.
- Client-side deadlines: --timeout / --shutdownAfter as context deadlines;
follow shutdown handling.
- Client logging: diagnostics-only daily log by default, opt-in payload tee via
--log-payload.
- Numerous correctness fixes (buffer-pool double-recycle races, EOF-sentinel
leaks, glob-expansion cap, TOCTOU in CSV parsing) with accompanying unit tests.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/io/dlog/dlog_test.go')
| -rw-r--r-- | internal/io/dlog/dlog_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/io/dlog/dlog_test.go b/internal/io/dlog/dlog_test.go new file mode 100644 index 0000000..87e834a --- /dev/null +++ b/internal/io/dlog/dlog_test.go @@ -0,0 +1,54 @@ +package dlog + +import "testing" + +// TestTraceEnabled verifies that TraceEnabled mirrors Trace's internal +// maxLevel < Trace early-return: it must report true exactly when the +// configured level is Trace or higher (Devel/All disable trace? no — the level +// ladder is monotonically increasing, so any level >= Trace enables trace), +// and false for every level below Trace. +func TestTraceEnabled(t *testing.T) { + tests := []struct { + name string + level level + want bool + }{ + {"none", None, false}, + {"fatal", Fatal, false}, + {"error", Error, false}, + {"warn", Warn, false}, + {"info", Info, false}, + {"default", Default, false}, + {"verbose", Verbose, false}, + {"debug", Debug, false}, + {"devel", Devel, false}, + {"trace", Trace, true}, + {"all", All, true}, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + d := &DLog{maxLevel: tc.level} + if got := d.TraceEnabled(); got != tc.want { + t.Fatalf("TraceEnabled() at level %v = %v, want %v", + tc.level, got, tc.want) + } + // TraceEnabled must agree with what Trace itself would do: Trace + // returns "" (no work) exactly when trace is disabled. + traceDidWork := d.maxLevel >= Trace + if traceDidWork != tc.want { + t.Fatalf("TraceEnabled() disagrees with Trace's own gate at level %v", tc.level) + } + }) + } +} + +// TestTraceEnabledNilSafe guards the footgun that call sites rely on: +// TraceEnabled is invoked on the package-level loggers (Server/Client/Common), +// which are nil until Start runs. A nil receiver must report false, not panic. +func TestTraceEnabledNilSafe(t *testing.T) { + var d *DLog + if d.TraceEnabled() { + t.Fatal("nil *DLog.TraceEnabled() must be false") + } +} |
