Ally/War commands

This commit is contained in:
Ilia Denisov
2025-09-28 22:43:27 +03:00
parent 6510676237
commit 128d6862a7
14 changed files with 315 additions and 74 deletions
+29 -1
View File
@@ -2,8 +2,10 @@ package game
import (
"fmt"
"path/filepath"
"testing"
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/pkg/repo"
"github.com/iliadenisov/galaxy/pkg/util"
"github.com/stretchr/testify/assert"
@@ -24,6 +26,32 @@ func TestNewGame(t *testing.T) {
assert.NoError(t, r.Lock())
gameID, err := newGame(r, races)
assert.NoError(t, err)
assert.FileExists(t, filepath.Join(root, "state.json"))
assert.FileExists(t, filepath.Join(root, "000/state.json"))
g, err := r.LoadState()
assert.NoError(t, err)
assert.Equal(t, gameID, g.ID)
assert.Equal(t, uint(0), g.Age)
assert.Equal(t, players, len(g.Race))
for r := range g.Race {
assert.NotEqual(t, uuid.Nil, g.Race[r].ID)
assert.Equal(t, players-1, len(g.Race[r].Relations))
for i := range g.Race[r].Relations {
assert.NotEqual(t, uuid.Nil, g.Race[r].Relations[i].RaceID)
if g.Race[r].Relations[i].RaceID == g.Race[r].ID {
assert.Fail(t, "race relation with itself")
}
}
}
numShuffled := false
for i := range g.Map.Planet {
numShuffled = numShuffled || g.Map.Planet[i].Number != uint(i)
}
assert.True(t, numShuffled)
assert.NoError(t, r.Release())
_ = gameID
}