Files
galaxy-game/internal/controller/race_test.go
T
2026-02-08 10:11:58 +02:00

44 lines
1.3 KiB
Go

package controller_test
import (
"testing"
e "github.com/iliadenisov/galaxy/internal/error"
"github.com/iliadenisov/galaxy/internal/model/game"
"github.com/stretchr/testify/assert"
)
func TestGiveVotes(t *testing.T) {
c, g := newCache()
assert.Equal(t, c.Voted(Race_0_idx), Race_0_idx)
assert.Equal(t, c.Voted(Race_1_idx), Race_1_idx)
assert.NoError(t, g.GiveVotes(Race_0.Name, Race_1.Name))
assert.Equal(t, Race_1_idx, c.Voted(Race_0_idx))
assert.Equal(t, Race_1_idx, c.Voted(Race_1_idx))
assert.ErrorContains(t, g.GiveVotes("UnknownRace", Race_1.Name), e.GenericErrorText(e.ErrInputUnknownRace))
assert.ErrorContains(t, g.GiveVotes(Race_0.Name, "UnknownRace"), e.GenericErrorText(e.ErrInputUnknownRace))
}
func TestRelation(t *testing.T) {
c, g := newCache()
assert.NoError(t, g.UpdateRelation(Race_0.Name, Race_1.Name, game.RelationWar))
assert.NoError(t, g.UpdateRelation(Race_1.Name, Race_0.Name, game.RelationPeace))
assert.Equal(t, game.RelationWar, c.Relation(Race_0_idx, Race_1_idx))
assert.Equal(t, game.RelationPeace, c.Relation(Race_1_idx, Race_0_idx))
c.WipeRace(Race_1_idx)
assert.ErrorContains(t,
g.UpdateRelation(Race_0.Name, Race_1.Name, game.RelationWar),
e.GenericErrorText(e.ErrRaceExinct))
assert.ErrorContains(t,
g.UpdateRelation(Race_1.Name, Race_0.Name, game.RelationWar),
e.GenericErrorText(e.ErrRaceExinct))
}