aboutsummaryrefslogtreecommitdiff
path: root/internal/game/hardening_craft_combat_helpers_test.go
blob: cfd860f74ca89caf26aabee7b5c681a74284f8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
	}
}