src to pkg, impl lobby.Closed
This commit is contained in:
53
pkg/state/lobby/lobby_test.go
Normal file
53
pkg/state/lobby/lobby_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package lobby_test
|
||||
|
||||
import (
|
||||
"gitea/price-is-wrong/pkg/lib"
|
||||
"gitea/price-is-wrong/pkg/state/lobby"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpen(t *testing.T) {
|
||||
ctx := lib.NewTestCtx(t)
|
||||
|
||||
l, err := lobby.Open(ctx, "id")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("%+v", l)
|
||||
|
||||
if len(l.Players) != 0 {
|
||||
t.Errorf("new lobby has players: %+v", l.Players)
|
||||
}
|
||||
|
||||
if err := l.Join(ctx, 1); err != nil {
|
||||
t.Fatal("failed to join:", err)
|
||||
} else if len(l.Players) != 1 {
|
||||
t.Errorf("wrong number of players after first join: %+v", l.Players)
|
||||
}
|
||||
|
||||
if err := l.Leave(ctx, 1); err != nil {
|
||||
t.Fatal("failed to join:", err)
|
||||
} else if len(l.Players) != 0 {
|
||||
t.Errorf("wrong number of players after only leaves: %+v", l.Players)
|
||||
}
|
||||
|
||||
if err := l.Join(ctx, 1); err != nil {
|
||||
t.Fatal("failed to join:", err)
|
||||
} else if err := l.Join(ctx, 1); err != nil {
|
||||
t.Fatal("failed to join redundant:", err)
|
||||
} else if len(l.Players) != 1 {
|
||||
t.Errorf("redundant join yielded wrong players: %+v", l.Players)
|
||||
}
|
||||
|
||||
if err := l.Join(ctx, 2); err != nil {
|
||||
t.Fatal("failed to second join:", err)
|
||||
} else if len(l.Players) != 2 {
|
||||
t.Errorf("second join yielded wrong players: %+v", l.Players)
|
||||
}
|
||||
|
||||
if err := l.Close(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !l.Closed {
|
||||
t.Error(l.Closed)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user