diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-27 18:33:40 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-27 18:33:40 +0200 |
| commit | 3783d23b8d608c3bf4a2dedd6b4bfb9165439bed (patch) | |
| tree | 69bf24794994d4cdd0e01e337de0510f7d5139b8 /internal/flags | |
| parent | 1cf64c3e43b1bdc2b6443fd24db8028f3c96c6da (diff) | |
internal: validate live CLI mode behavior
Diffstat (limited to 'internal/flags')
| -rw-r--r-- | internal/flags/flags_test.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go new file mode 100644 index 0000000..b4d47d2 --- /dev/null +++ b/internal/flags/flags_test.go @@ -0,0 +1,76 @@ +package flags + +import ( + "flag" + "io" + "os" + "sync" + "testing" + "time" +) + +func parseForTest(t *testing.T, args ...string) Flags { + t.Helper() + + oldCommandLine := flag.CommandLine + oldArgs := os.Args + oldSingleton := singleton + oldOnce := once + oldPID := pidFilter.Load() + oldTID := tidFilter.Load() + oldTUIExport := tuiExportEnable.Load() + + fs := flag.NewFlagSet("ior-test", flag.ContinueOnError) + fs.SetOutput(io.Discard) + flag.CommandLine = fs + os.Args = append([]string{"ior"}, args...) + + singleton = Flags{TUIExportEnable: true} + once = sync.Once{} + pidFilter.Store(-1) + tidFilter.Store(-1) + tuiExportEnable.Store(true) + + parse() + cfg := singleton + + t.Cleanup(func() { + flag.CommandLine = oldCommandLine + os.Args = oldArgs + singleton = oldSingleton + once = oldOnce + pidFilter.Store(oldPID) + tidFilter.Store(oldTID) + tuiExportEnable.Store(oldTUIExport) + }) + + return cfg +} + +func TestParseLiveFlagsAndInterval(t *testing.T) { + cfg := parseForTest(t, "-live", "-live-interval", "200ms", "-pid", "1234") + + if !cfg.LiveFlamegraph { + t.Fatalf("expected -live to enable live mode") + } + if cfg.LiveInterval != 200*time.Millisecond { + t.Fatalf("live interval = %v, want %v", cfg.LiveInterval, 200*time.Millisecond) + } + if cfg.PidFilter != 1234 { + t.Fatalf("pid filter = %d, want 1234", cfg.PidFilter) + } + if got := int(pidFilter.Load()); got != 1234 { + t.Fatalf("global pid filter = %d, want 1234", got) + } +} + +func TestParseLiveDefaults(t *testing.T) { + cfg := parseForTest(t) + + if cfg.LiveFlamegraph { + t.Fatalf("expected live mode disabled by default") + } + if cfg.LiveInterval != time.Second { + t.Fatalf("default live interval = %v, want %v", cfg.LiveInterval, time.Second) + } +} |
