DEV 559: Refactor CLI and add customizations (#57)
* move snake API structs into a new client package * add customizations to snake objects * refactor and add support for passing snake customizations in games
This commit is contained in:
parent
6140f232c2
commit
4a9dbbcaef
10 changed files with 665 additions and 197 deletions
|
|
@ -1,35 +0,0 @@
|
|||
package rules
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var updateFixtures = flag.Bool("update-fixtures", false, "Regenerate fixtures in testdata based on current test output")
|
||||
|
||||
// RequireJSONMatchesFixture asserts that the JSON text in actual matches the
|
||||
// JSON read from filename, without taking into account whitespace and
|
||||
// ordering. Files can be specified relative to the calling test (e.g.
|
||||
// testdata/example.json). To regenerate the expected test data automatically
|
||||
// after making a code change, pass the `-update-fixtures` flag to `go test`.
|
||||
func RequireJSONMatchesFixture(t *testing.T, filename string, actual string) {
|
||||
t.Helper()
|
||||
|
||||
if *updateFixtures {
|
||||
var indented bytes.Buffer
|
||||
err := json.Indent(&indented, []byte(actual), "", " ")
|
||||
require.NoError(t, err, "Failed to indent JSON")
|
||||
err = ioutil.WriteFile(filename, indented.Bytes(), 0644)
|
||||
require.NoError(t, err, "Failed to update fixture", filename)
|
||||
}
|
||||
|
||||
expectedData, err := ioutil.ReadFile(filename)
|
||||
require.NoError(t, err, "Failed to read fixture", filename)
|
||||
|
||||
require.JSONEq(t, string(expectedData), actual)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue