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:
Rob O'Dwyer 2021-11-25 14:07:56 -08:00 committed by GitHub
parent 6140f232c2
commit 4a9dbbcaef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 665 additions and 197 deletions

38
test/test_utils.go Normal file
View file

@ -0,0 +1,38 @@
package test
import (
"bytes"
"encoding/json"
"flag"
"io/ioutil"
"log"
"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)
log.Printf("Updating fixture file %#v", filename)
}
expectedData, err := ioutil.ReadFile(filename)
require.NoError(t, err, "Failed to read fixture", filename)
require.JSONEq(t, string(expectedData), actual)
}