package router_test import ( "encoding/json" "net/http" "galaxy/model/order" "galaxy/model/report" "galaxy/model/rest" "galaxy/game/internal/router" "galaxy/game/internal/router/handler" "github.com/gin-gonic/gin" "github.com/google/uuid" ) var ( commandNoErrorsStatus = http.StatusNoContent commandDefaultActor = "Gorlum" apiCommandMethod = "PUT" apiCommandPath = "/api/v1/command" apiOrderPath = "/api/v1/order" validId1 = id() validId2 = id() invalidId = "fd091c69-5976-4775-b2f9-7ba77735afb" ) func id() string { return uuid.New().String() } type dummyExecutor struct { CommandsExecuted int } func (e *dummyExecutor) ValidateOrder(actor string, cmd ...order.DecodableCommand) error { e.CommandsExecuted = len(cmd) return nil } func (e *dummyExecutor) Execute(command ...handler.Command) error { e.CommandsExecuted = len(command) return nil } func (e *dummyExecutor) GenerateGame(races []string) (rest.StateResponse, error) { return rest.StateResponse{}, nil } func (e *dummyExecutor) GenerateTurn() (rest.StateResponse, error) { return rest.StateResponse{}, nil } func (e *dummyExecutor) BanishRace(raceName string) error { return nil } func (e *dummyExecutor) GameState() (rest.StateResponse, error) { return rest.StateResponse{}, nil } func (e *dummyExecutor) LoadReport(actor string, turn uint) (*report.Report, error) { return &report.Report{}, nil } func setupRouter() *gin.Engine { return setupRouterExecutor(newExecutor()) } func setupRouterExecutor(e handler.CommandExecutor) *gin.Engine { return router.SetupRouter(e) } func newExecutor() handler.CommandExecutor { return &dummyExecutor{} } func encodeCommand(cmd any) json.RawMessage { v, err := json.Marshal(cmd) if err != nil { panic(err) } return v }