out/cmd/server/usergameserver_test.go

96 lines
1.8 KiB
Go

package main
import (
"context"
"fmt"
"testing"
)
func TestUserGameServer(t *testing.T) {
ctx := context.Background()
games := newTestGames(t)
gid, err := games.CreateGame(ctx, "g1")
if err != nil {
t.Fatal(err)
}
pids := []string{}
for i := 0; i < 4; i++ {
pid := fmt.Sprintf("p%d", i+1)
if err := games.CreateEventPlayerJoin(ctx, gid, pid, "player "+pid); err != nil {
t.Fatal(err)
}
pids = append(pids, pid)
}
ugs, err := NewUserGameServer(ctx, Session{ID: pids[0]}, games)
if err != nil {
t.Fatal(err)
}
t.Run("unstarted", func(t *testing.T) {
state, err := ugs.State(ctx)
if err != nil {
t.Fatal(err)
}
if state.Started {
t.Error("started after player joins only")
}
if !state.Completed.IsZero() {
t.Error("completed after player joins only")
}
for _, pid := range pids {
if p, ok := state.Players[pid]; !ok {
t.Error(pid, "not in players")
} else if !p.Empty() {
t.Error(pid, p)
}
}
})
if err := games.CreateEventAssignmentRotation(ctx, gid, "", "", "", 0); err != nil {
t.Fatal(err)
}
t.Run("started but no kills", func(t *testing.T) {
state, err := ugs.State(ctx)
if err != nil {
t.Fatal(err)
}
if !state.Started {
t.Error("not started after assignment rotation")
}
if !state.Completed.IsZero() {
t.Error("completed after assignment rotation")
}
for _, pid := range pids {
if p, ok := state.Players[pid]; !ok {
t.Error(pid, "not in players")
} else if p.Empty() {
t.Error(pid, p)
}
if isSelf := pid == ugs.Session.ID; isSelf {
t.Error("not impl")
} else {
t.Error("not impl")
}
}
})
t.Run("started with kills", func(t *testing.T) {
t.Error("not impl")
})
t.Run("completed", func(t *testing.T) {
t.Error("not impl")
})
}