package game_test import ( "testing" "github.com/iliadenisov/galaxy/internal/controller" e "github.com/iliadenisov/galaxy/internal/error" "github.com/iliadenisov/galaxy/internal/game" mg "github.com/iliadenisov/galaxy/internal/model/game" "github.com/stretchr/testify/assert" ) func TestDeclarePeaceAndWarSingle(t *testing.T) { g(t, func(f func(*controller.Param), g func() mg.Game) { hostRace := "race_05" opponentRace := "race_01" r, err := g().Relation(hostRace, opponentRace) assert.NoError(t, err) assert.Equal(t, mg.RelationWar, r.Relation) r, err = g().Relation(unknownRaceName, opponentRace) // TODO: test on dead race assert.ErrorContains(t, err, e.GenericErrorText(e.ErrInputUnknownRace)) r, err = g().Relation(hostRace, unknownRaceName) // TODO: test on dead race assert.ErrorContains(t, err, e.GenericErrorText(e.ErrInputUnknownRace)) assert.NoError(t, game.DeclarePeace(f, hostRace, opponentRace)) r, err = g().Relation(hostRace, opponentRace) assert.NoError(t, err) assert.Equal(t, mg.RelationPeace, r.Relation) assert.NoError(t, game.DeclareWar(f, hostRace, opponentRace)) r, err = g().Relation(hostRace, opponentRace) assert.NoError(t, err) assert.Equal(t, mg.RelationWar, r.Relation) }) } func TestDeclarePeaceAndWarAll(t *testing.T) { g(t, func(f func(*controller.Param), g func() mg.Game) { hostRace := "race_07" for i := range testRaceCount { opponentRace := raceNum(i) if opponentRace == hostRace { continue } r, err := g().Relation(hostRace, opponentRace) assert.NoError(t, err) assert.Equal(t, mg.RelationWar, r.Relation) } assert.NoError(t, game.DeclarePeace(f, hostRace, hostRace)) for i := range testRaceCount { opponentRace := raceNum(i) if opponentRace == hostRace { continue } r, err := g().Relation(hostRace, opponentRace) assert.NoError(t, err) assert.Equal(t, mg.RelationPeace, r.Relation) } assert.NoError(t, game.DeclareWar(f, hostRace, hostRace)) for i := range testRaceCount { opponentRace := raceNum(i) if opponentRace == hostRace { continue } r, err := g().Relation(hostRace, opponentRace) assert.NoError(t, err) assert.Equal(t, mg.RelationWar, r.Relation) } }) }