aboutsummaryrefslogtreecommitdiff
path: root/internal/game/hardening_craft_combat_helpers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/hardening_craft_combat_helpers_test.go')
-rw-r--r--internal/game/hardening_craft_combat_helpers_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/game/hardening_craft_combat_helpers_test.go b/internal/game/hardening_craft_combat_helpers_test.go
new file mode 100644
index 0000000..cfd860f
--- /dev/null
+++ b/internal/game/hardening_craft_combat_helpers_test.go
@@ -0,0 +1,40 @@
+package game
+
+// Shared helpers for the crafting/combat hardening regressions. The tests
+// build a real Game (owner loop, stores, craft index) over a temp data dir
+// but deliberately do NOT start a background ticker, so each test drives
+// production/combat cycles with explicit calls and asserts without racing
+// Game.AdvanceActions.
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "thehouseoficarus/internal/config"
+ "thehouseoficarus/internal/net"
+)
+
+// newHardeningGame builds a real Game over dir with an owner loop but no
+// background ticker. stopOwner is registered for cleanup so the owner
+// goroutine does not leak.
+func newHardeningGame(t *testing.T, dir string) *Game {
+ t.Helper()
+ colors := &config.ColorsConfig{}
+ g := New(dir, colors, colors, config.ValidationConfig{}, 1)
+ g.SetHub(net.NewHub())
+ t.Cleanup(g.stopOwner)
+ return g
+}
+
+// writeDataFile writes subdir/name under dir, creating parent directories.
+func writeDataFile(t *testing.T, dir, subdir, name, content string) {
+ t.Helper()
+ path := filepath.Join(dir, subdir, name)
+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
+ t.Fatalf("mkdir %s: %v", subdir, err)
+ }
+ if err := os.WriteFile(path, []byte(content), 0644); err != nil {
+ t.Fatalf("write %s: %v", path, err)
+ }
+}