Documentation
¶
Overview ¶
Package mockgame is a tiny game that the lobby calls over HTTP, for the lobby's own tests. It serves the hooks of the gamehooks protocol from Go functions, keeps its games in memory, reads the lobby through the game API, and can be told to fail or delay a hook.
- Its game settings are {"rounds": N}, N from 1 to 5.
- Its seats are {"level": 1}, named "Mock bot (level 1)". A seat may also name the player who adds it, {"level": 1, "added_by": "<player ID>"}, which validate-seat accepts only from that player.
- Its member settings are {"color": "<1 to 20 characters>"}, and a person needs them to get ready: ready-check refuses a member without them with the problem type ColorMissingProblemType.
- start records a game for the lobby's round, once: a second call for the same round returns the same game.
- POST /finish/{lobby_id} ends the game of the lobby's newest round, so round-ended answers true and the lobby can be reopened.
- GET /watch/{lobby_id}?player_id=… is a watcher's read: it asks the lobby's game API whether the player may watch, and answers with the lobby's game.
A Game is an http.Handler; serve it with httptest.NewServer and configure the lobby with hooks_url set to the server's URL + HooksPath.
Index ¶
- Constants
- func ValidateSignedInOnly(_ context.Context, _ string, member domain.MemberIdentity, ...) error
- type Game
- func (game *Game) Calls(hook string) int
- func (game *Game) Delay(hook string, delay time.Duration, times int)
- func (game *Game) Fail(hook string, status, times int)
- func (game *Game) Finish(lobbyID string) bool
- func (game *Game) Games() []StartedGame
- func (game *Game) Registration() domain.GameRegistration
- func (game *Game) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (game *Game) UseLobby(client *gamehooks.GameAPIClient)
- type StartedGame
- type Watch
Constants ¶
const ( GoogleCertsPath = "/google/certs" GoogleIDTokenPath = "/google/id-token" )
The mock game's stand-in for Google, for live tests of Sign in with Google: GoogleCertsPath serves its keys, which a lobby verifies ID tokens with when its LOBBY_GOOGLE_CERTS_URL points there, and GoogleIDTokenPath signs an ID token for the JSON body {"subject", "audience"}, as {"credential"}.
const ColorMissingProblemType = "urn:mockgame:problem:color-missing"
ColorMissingProblemType is the ready-check's refusal of a member who has chosen no color.
const HooksPath = "/hooks"
HooksPath is where a Game serves its hooks.
const MaxRounds = 5
MaxRounds bounds the rounds setting.
const SeatName = "Mock bot (level 1)"
SeatName names the mock game's only seat.
Variables ¶
This section is empty.
Functions ¶
func ValidateSignedInOnly ¶ added in v0.6.0
func ValidateSignedInOnly(_ context.Context, _ string, member domain.MemberIdentity, settings json.RawMessage) error
ValidateSignedInOnly is the mock game's member settings check without its rules: it takes only {"signed_in": true}, and only from a member who signed in, so a live suite proves that the lobby tells the game who sets them.
Types ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game is the mock game.
func (*Game) Calls ¶
Calls counts the signed calls of hook that reached the game, failed ones included.
func (*Game) Delay ¶
Delay makes the next times calls of hook wait for delay first, or until the call is canceled.
func (*Game) Fail ¶
Fail makes the next times calls of hook answer status, with a problem, without running the hook.
func (*Game) Finish ¶
Finish ends the game of the lobby's newest round, and reports whether there was one.
func (*Game) Games ¶
func (game *Game) Games() []StartedGame
Games returns the recorded games, by lobby and round.
func (*Game) Registration ¶
func (game *Game) Registration() domain.GameRegistration
Registration is the mock game's hooks as Go functions, which NewHandler serves. The key is the game's; its start rules and retention are the lobby configuration's.
func (*Game) ServeHTTP ¶
func (game *Game) ServeHTTP(response http.ResponseWriter, request *http.Request)
func (*Game) UseLobby ¶
func (game *Game) UseLobby(client *gamehooks.GameAPIClient)
UseLobby connects the game to the lobby's game API, for GET /watch.
type StartedGame ¶
type StartedGame struct {
ID string
LobbyID string
Round int64
// Players are the start roster's player IDs, in roster order.
Players []string
// Colors are the people's colors by player ID, from their member
// settings.
Colors map[string]string
Ended bool
}
StartedGame is a game that start recorded for a lobby's round.