diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-05 23:50:27 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-05 23:50:27 +0200 |
| commit | 581337620db24bc654c5e1c5fb6fb251770aada1 (patch) | |
| tree | 0537b6963799d3e802ed27990348a76f805b21de /internal/flags/flags_test.go | |
| parent | 77310af6f292004fbdd11eaa0bcfeaff812a365d (diff) | |
Refactor flags state to constructor-backed snapshots
Diffstat (limited to 'internal/flags/flags_test.go')
| -rw-r--r-- | internal/flags/flags_test.go | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go index 54c65b8..3534916 100644 --- a/internal/flags/flags_test.go +++ b/internal/flags/flags_test.go @@ -14,34 +14,25 @@ func parseForTest(t *testing.T, args ...string) (Flags, error) { oldCommandLine := flag.CommandLine oldArgs := os.Args - oldSingleton := singleton + oldCurrent := Get() oldParseErr := parseErr - 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} + setCurrent(NewFlags()) parseErr = nil - pidFilter.Store(-1) - tidFilter.Store(-1) - tuiExportEnable.Store(true) err := parse() - cfg := singleton + cfg := Get() t.Cleanup(func() { flag.CommandLine = oldCommandLine os.Args = oldArgs - singleton = oldSingleton + setCurrent(oldCurrent) parseErr = oldParseErr - pidFilter.Store(oldPID) - tidFilter.Store(oldTID) - tuiExportEnable.Store(oldTUIExport) }) return cfg, err @@ -62,14 +53,30 @@ func TestParseLiveFlagsAndInterval(t *testing.T) { 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) + if got := Get().GetPidFilter(); got != 1234 { + t.Fatalf("Get().GetPidFilter() = %d, want 1234", got) } if cfg.OpenCommand != "" { t.Fatalf("expected empty open command by default") } } +func TestNewFlagsDefaultsAndGetters(t *testing.T) { + cfg := NewFlags() + if cfg.GetPidFilter() != -1 { + t.Fatalf("GetPidFilter() = %d, want -1", cfg.GetPidFilter()) + } + if cfg.GetTidFilter() != -1 { + t.Fatalf("GetTidFilter() = %d, want -1", cfg.GetTidFilter()) + } + if !cfg.GetTUIExportEnable() { + t.Fatalf("GetTUIExportEnable() = false, want true") + } + if cfg.CountField != "count" { + t.Fatalf("CountField = %q, want count", cfg.CountField) + } +} + func TestParseLiveDefaults(t *testing.T) { cfg, err := parseForTest(t) if err != nil { |
