poker

package module
v0.0.0-...-38385e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2019 License: MIT Imports: 20 Imported by: 0

README

go-fast

This is the learn-go-with-tests application, fully deployed through CI/CD

Test

$ docker-compose -f local.yml run --rm app go test -v

IMPORTANT NOTE

The production build does not include a go installation, only the compiled app binary; it will be impossible to run unit tests on the production build

Deploy

To serve locally

Build the app:

~$ docker-compose -f local.yml build

then:

~$ docker-compose -f local.yml up

You can set the environment variable COMPOSE_FILE to avoid typing it every time

~$ export COMPOSE_FILE=local.yml
~$ docker-compose up --build

(up with --build flag builds [if necessary] and serves in one command)

Deployment Checklist:
  • Target machine has docker (>=18.09) && docker-compose (>=1.23.1) installed
  • Target user belongs to the docker group (so user can run docker without elevation)
    • Run sudo usermod -aG docker $USER
Staging build

It runs a single instance, with a static traefik config. Requires no setup other than the commands below. This will be used for the E2E suite (not yet implemented).

Set the DOCKER_HOST environment variable

$ export DOCKER_HOST=ssh://user@host
$ docker-compose -f staging.yml up --detach --build

or run the -H parameter to docker-compose:

$ docker-compose -H "ssh://user@host" -f staging.yml up --build --detach
Production build

Load balanced, scalable build (not yet implemented)

Documentation

Index

Constants

View Source
const BadPlayerInputErrMsg = "Bad value received for number of players, please try again with a number"
View Source
const JsonContentType = "application/json"
View Source
const PlayerPrompt = "Please enter the number of players: "

Variables

View Source
var DummyGame = &GameSpy{}
View Source
var ErrRecordAlreadyExists = errors.New("already exists")

Functions

func Alerter

func Alerter(duration time.Duration, amount int, to io.Writer)

StdOutAlerter prints alerts through stdout

func AssertContentType

func AssertContentType(t *testing.T, response *httptest.ResponseRecorder, want string)

func AssertError

func AssertError(t *testing.T, got, want error)

func AssertFinishCalledWith

func AssertFinishCalledWith(t *testing.T, gameSpy *GameSpy, want string)

func AssertGameStartedWith

func AssertGameStartedWith(t *testing.T, gameSpy *GameSpy, want int)

func AssertLeague

func AssertLeague(t *testing.T, got, want League)

func AssertMessagesSentToUser

func AssertMessagesSentToUser(t *testing.T, stdout *bytes.Buffer, messages ...string)

func AssertNoError

func AssertNoError(t *testing.T, got error)

func AssertPlayerWin

func AssertPlayerWin(t *testing.T, store *StubPlayerStore, winner string)

func AssertResponseBody

func AssertResponseBody(t *testing.T, got, want string)

func AssertScheduledAlert

func AssertScheduledAlert(t *testing.T, got, want ScheduledAlert)

func AssertScoreEquals

func AssertScoreEquals(t *testing.T, got, want int)

func AssertStatus

func AssertStatus(t *testing.T, got, want int)

func CheckSchedulingCases

func CheckSchedulingCases(cases []ScheduledAlert, t *testing.T, blindAlerter *SpyBlindAlerter)

func CreateTempFile

func CreateTempFile(t *testing.T, initialData string) (io.ReadWriteSeeker, func())

func MustDialWS

func MustDialWS(t *testing.T, url string) *websocket.Conn

func NewGameRequest

func NewGameRequest() *http.Request

func NewGetScoreRequest

func NewGetScoreRequest(name string) *http.Request

func NewLeagueRequest

func NewLeagueRequest() *http.Request

func NewPostWinRequest

func NewPostWinRequest(name string) *http.Request

func WriteWSMessage

func WriteWSMessage(t *testing.T, conn *websocket.Conn, message string)

Types

type BlindAlerter

type BlindAlerter interface {
	ScheduleAlertAt(duration time.Duration, amount int, to io.Writer)
}

type BlindAlerterFunc

type BlindAlerterFunc func(duration time.Duration, amount int, to io.Writer)

func (BlindAlerterFunc) ScheduleAlertAt

func (a BlindAlerterFunc) ScheduleAlertAt(duration time.Duration, amount int, to io.Writer)

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

func NewCLI

func NewCLI(in io.Reader, out io.Writer, game Game) *CLI

func (*CLI) PlayPoker

func (cli *CLI) PlayPoker()

type Game

type Game interface {
	Start(numberOfPlayers int, alertsDestination io.Writer)
	Finish(winner string)
}

type GameSpy

type GameSpy struct {
	StartedWith  int
	FinishedWith string
	StartCalled  bool
}

func (*GameSpy) Finish

func (g *GameSpy) Finish(winner string)

func (*GameSpy) Start

func (g *GameSpy) Start(numberOfPlayers int, alertsDestination io.Writer)

type League

type League []Player

func GetLeagueFromResponse

func GetLeagueFromResponse(t *testing.T, body io.Reader) (league League)

func NewLeague

func NewLeague(rdr io.Reader) (League, error)

func (League) Find

func (l League) Find(name string) *Player

type Player

type Player struct {
	ID   int    `sql:"column:id;" json:"id"`
	Name string `sql:"column:name;" json:"name"`
	Wins int    `sql:"columns:wins;" json:"wins"`
}

Player struct to hold base data

type PlayerServer

type PlayerServer struct {
	http.Handler
	// contains filtered or unexported fields
}

func MustMakePlayerServer

func MustMakePlayerServer(t *testing.T, store PlayerStore, spy *GameSpy) *PlayerServer

func NewPlayerServer

func NewPlayerServer(store PlayerStore, game Game) (*PlayerServer, error)

type PlayerStore

type PlayerStore interface {
	GetPlayerScore(name string) int
	RecordWin(name string)
	GetLeague() League
}

PlayerStore interface

type PostgreSQLPlayerStore

type PostgreSQLPlayerStore struct {
	DB *sql.DB
}

PostgreSQLPlayerStore

func NewPostgreSQLPlayerStore

func NewPostgreSQLPlayerStore(host, port, user, dbname, pass string) (*PostgreSQLPlayerStore, func())

func (*PostgreSQLPlayerStore) GetLeague

func (s *PostgreSQLPlayerStore) GetLeague() League

func (*PostgreSQLPlayerStore) GetPlayerScore

func (s *PostgreSQLPlayerStore) GetPlayerScore(name string) int

func (*PostgreSQLPlayerStore) RecordWin

func (s *PostgreSQLPlayerStore) RecordWin(name string)

type ScheduledAlert

type ScheduledAlert struct {
	At     time.Duration
	Amount int
}

func (ScheduledAlert) String

func (s ScheduledAlert) String() string

type SpyBlindAlerter

type SpyBlindAlerter struct {
	Alerts []ScheduledAlert
}

func (*SpyBlindAlerter) ScheduleAlertAt

func (s *SpyBlindAlerter) ScheduleAlertAt(at time.Duration, amount int, to io.Writer)

type StubPlayerStore

type StubPlayerStore struct {
	Scores   map[string]int
	WinCalls []string
	League   League
}

func NewStubPlayerStore

func NewStubPlayerStore(
	initialData map[string]int,
	initialWinCalls []string,
	initialLeague League,
) *StubPlayerStore

func (*StubPlayerStore) GetLeague

func (s *StubPlayerStore) GetLeague() League

func (*StubPlayerStore) GetPlayerScore

func (s *StubPlayerStore) GetPlayerScore(name string) int

func (*StubPlayerStore) RecordWin

func (s *StubPlayerStore) RecordWin(name string)

type TexasHoldem

type TexasHoldem struct {
	Alerter BlindAlerter
	Store   PlayerStore
}

func NewTexasHoldem

func NewTexasHoldem(alerter BlindAlerter, store PlayerStore) *TexasHoldem

func (*TexasHoldem) Finish

func (p *TexasHoldem) Finish(winner string)

func (*TexasHoldem) Start

func (p *TexasHoldem) Start(numberOfPlayers int)

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL