src to pkg, impl lobby.Closed

This commit is contained in:
Bel LaPointe
2025-02-12 16:48:58 -07:00
parent 1f6b79aa3b
commit e35ddef4b7
18 changed files with 117 additions and 21 deletions

View 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)
}
}