From 490cd9a0d86b6b7aa094e9bff778a408c9e55441 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 4 Mar 2026 08:20:01 +0200 Subject: tests: skip IO-heavy suites in short mode --- internal/config/config_test.go | 16 ++++++++++++++++ internal/timer/operations_test.go | 3 +++ internal/worktime/db_test.go | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 6332d09..2552cd9 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -8,6 +8,13 @@ import ( "testing" ) +func skipIOHeavyInShort(t *testing.T) { + t.Helper() + if testing.Short() { + t.Skip("skipping filesystem-heavy config tests in short mode") + } +} + func TestDefault(t *testing.T) { cfg := Default() @@ -45,6 +52,7 @@ func TestDefault(t *testing.T) { } func TestLoadMissingFileReturnsDefaults(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) @@ -65,6 +73,7 @@ func TestLoadMissingFileReturnsDefaults(t *testing.T) { } func TestLoadAppliesDefaultsAndExpandsWorktimeDir(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) @@ -102,6 +111,7 @@ func TestLoadAppliesDefaultsAndExpandsWorktimeDir(t *testing.T) { } func TestLoadPreservesExplicitEmptyLists(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) @@ -127,6 +137,7 @@ func TestLoadPreservesExplicitEmptyLists(t *testing.T) { } func TestLoadInvalidJSON(t *testing.T) { + skipIOHeavyInShort(t) cfgPath := filepath.Join(t.TempDir(), "config.json") if err := os.WriteFile(cfgPath, []byte(`{"weekworkhours":`), 0o644); err != nil { t.Fatalf("WriteFile() error = %v", err) @@ -143,6 +154,7 @@ func TestLoadInvalidJSON(t *testing.T) { } func TestSaveAndLoadRoundTrip(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) @@ -194,6 +206,7 @@ func TestSaveAndLoadRoundTrip(t *testing.T) { } func TestSaveAndLoadUsingDefaultPath(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) t.Setenv("XDG_CONFIG_HOME", filepath.Join(tempHome, ".config")) @@ -239,6 +252,7 @@ func TestEffectiveHostnamePrefersConfigValue(t *testing.T) { } func TestEffectiveHostnameUsesOverrideFile(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) @@ -259,6 +273,7 @@ func TestEffectiveHostnameUsesOverrideFile(t *testing.T) { } func TestEffectiveHostnameFallsBackToOSHostname(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) @@ -279,6 +294,7 @@ func TestEffectiveHostnameFallsBackToOSHostname(t *testing.T) { } func TestEffectiveHostnameIgnoresEmptyOverride(t *testing.T) { + skipIOHeavyInShort(t) tempHome := t.TempDir() t.Setenv("HOME", tempHome) diff --git a/internal/timer/operations_test.go b/internal/timer/operations_test.go index 5c73db6..c0480d7 100644 --- a/internal/timer/operations_test.go +++ b/internal/timer/operations_test.go @@ -10,6 +10,9 @@ import ( // setup sets up a temporary state file for testing. func setup(t *testing.T) { t.Helper() + if testing.Short() { + t.Skip("skipping timer integration-style tests in short mode") + } tempDir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", tempDir) t.Setenv("HOME", tempDir) diff --git a/internal/worktime/db_test.go b/internal/worktime/db_test.go index f599fa1..cd0c43a 100644 --- a/internal/worktime/db_test.go +++ b/internal/worktime/db_test.go @@ -7,7 +7,15 @@ import ( "testing" ) +func skipIfShort(t *testing.T) { + t.Helper() + if testing.Short() { + t.Skip("skipping filesystem-heavy worktime db tests in short mode") + } +} + func TestLoadHostMissingFileReturnsEmptyDatabase(t *testing.T) { + skipIfShort(t) dbDir := t.TempDir() db, err := LoadHost(dbDir, "host-a") @@ -25,6 +33,7 @@ func TestLoadHostMissingFileReturnsEmptyDatabase(t *testing.T) { } func TestLoadHostRejectsEmptyHostname(t *testing.T) { + skipIfShort(t) _, err := LoadHost(t.TempDir(), "") if err == nil { t.Fatal("LoadHost() error = nil, want error") @@ -32,6 +41,7 @@ func TestLoadHostRejectsEmptyHostname(t *testing.T) { } func TestSaveHostRejectsEmptyHostname(t *testing.T) { + skipIfShort(t) err := SaveHost(t.TempDir(), " ", Database{}) if err == nil { t.Fatal("SaveHost() error = nil, want error") @@ -39,6 +49,7 @@ func TestSaveHostRejectsEmptyHostname(t *testing.T) { } func TestSaveHostAndLoadHostRoundTrip(t *testing.T) { + skipIfShort(t) dbDir := filepath.Join(t.TempDir(), "nested", "db") host := "workstation" @@ -90,6 +101,7 @@ func TestSaveHostAndLoadHostRoundTrip(t *testing.T) { } func TestLoadAllMergesAndSortsEntries(t *testing.T) { + skipIfShort(t) dbDir := t.TempDir() dbA := Database{ @@ -130,6 +142,7 @@ func TestLoadAllMergesAndSortsEntries(t *testing.T) { } func TestLoadAllBackfillsMissingSourceFromHost(t *testing.T) { + skipIfShort(t) dbDir := t.TempDir() dbFile := filepath.Join(dbDir, "db.host-a.json") content := `{ @@ -156,6 +169,7 @@ func TestLoadAllBackfillsMissingSourceFromHost(t *testing.T) { } func TestLoadAllOnMissingDirectoryReturnsEmptySlice(t *testing.T) { + skipIfShort(t) dbDir := filepath.Join(t.TempDir(), "does-not-exist") entries, err := LoadAll(dbDir) @@ -169,6 +183,7 @@ func TestLoadAllOnMissingDirectoryReturnsEmptySlice(t *testing.T) { } func TestLoadHostInvalidJSON(t *testing.T) { + skipIfShort(t) dbDir := t.TempDir() badFile := filepath.Join(dbDir, "db.host-a.json") if err := os.WriteFile(badFile, []byte(`{"entries":`), 0o644); err != nil { @@ -186,6 +201,7 @@ func TestLoadHostInvalidJSON(t *testing.T) { } func TestLoadAllAcceptsFloatValueEncoding(t *testing.T) { + skipIfShort(t) dbDir := t.TempDir() dbFile := filepath.Join(dbDir, "db.host-a.json") content := `{ @@ -212,6 +228,7 @@ func TestLoadAllAcceptsFloatValueEncoding(t *testing.T) { } func TestLoadAllInvalidJSON(t *testing.T) { + skipIfShort(t) dbDir := t.TempDir() badFile := filepath.Join(dbDir, "db.host-a.json") if err := os.WriteFile(badFile, []byte(`{"entries":`), 0o644); err != nil { @@ -225,6 +242,7 @@ func TestLoadAllInvalidJSON(t *testing.T) { } func TestLoadAllRejectsEmptyDirectory(t *testing.T) { + skipIfShort(t) _, err := LoadAll("") if err == nil { t.Fatal("LoadAll() error = nil, want error") -- cgit v1.2.3