* Initial addition of a game exporter * Fix snake state bug, remove test logs, fix final output line being empty * Ignore test JSONL file * Added explanation for design decision on the you key in SnakeResponse * Adjust gitignore to be more generic * Retain consistency in usage of pointer * Re-word explanation to refer to requests instead of responses * Remove unnecessary nil check * Check error returned by WriteString * Change file permissions for output file * Initialise gameexporter regardless of whether output is requested * Print error and exit if export to file fails * Added another comment explaining reasoning around export checks * Fixed broken test due to changed return type
42 lines
1 KiB
Go
42 lines
1 KiB
Go
package commands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/BattlesnakeOfficial/rules"
|
|
"github.com/BattlesnakeOfficial/rules/test"
|
|
)
|
|
|
|
func TestGetIndividualBoardStateForSnake(t *testing.T) {
|
|
s1 := rules.Snake{ID: "one", Body: []rules.Point{{X: 3, Y: 3}}}
|
|
s2 := rules.Snake{ID: "two", Body: []rules.Point{{X: 4, Y: 3}}}
|
|
state := &rules.BoardState{
|
|
Height: 11,
|
|
Width: 11,
|
|
Snakes: []rules.Snake{s1, s2},
|
|
}
|
|
s1State := SnakeState{
|
|
ID: "one",
|
|
Name: "ONE",
|
|
URL: "http://example1.com",
|
|
Head: "safe",
|
|
Tail: "curled",
|
|
Color: "#123456",
|
|
}
|
|
s2State := SnakeState{
|
|
ID: "two",
|
|
Name: "TWO",
|
|
URL: "http://example2.com",
|
|
Head: "silly",
|
|
Tail: "bolt",
|
|
Color: "#654321",
|
|
}
|
|
snakeStates := map[string]SnakeState{
|
|
s1State.ID: s1State,
|
|
s2State.ID: s2State,
|
|
}
|
|
snakeRequest := getIndividualBoardStateForSnake(state, s1State, snakeStates, &rules.StandardRuleset{})
|
|
requestBody := serialiseSnakeRequest(snakeRequest)
|
|
|
|
test.RequireJSONMatchesFixture(t, "testdata/snake_request_body.json", string(requestBody))
|
|
}
|