From 3f967b571f8073ad254bb65713baa718a9390693 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 6 Nov 2021 20:24:01 +0000 Subject: [PATCH] feat(assert): add marshaling assertion helpers for JSON, YAML and XML --- .gitignore | 5 +- assert.go | 307 +++++++++++++++ assert_example_test.go | 68 ++++ assert_test.go | 370 ++++++++++++++++++ go.mod | 1 + go.sum | 3 +- golden.go | 77 +++- example_test.go => golden_example_test.go | 0 marshal_asserter.go | 151 +++++++ .../custom_marshaling/marshaled_json.golden | 3 + .../empty_struct/marshaled_json.golden | 4 + .../false_bool_pointer/marshaled_json.golden | 1 + .../full_struct/marshaled_json.golden | 9 + .../int_pointer/marshaled_json.golden | 1 + .../partial_struct/marshaled_json.golden | 4 + .../string_pointer/marshaled_json.golden | 1 + .../true_bool_pointer/marshaled_json.golden | 1 + .../custom_marshaling/marshaled_json.golden | 3 + .../empty_struct/marshaled_json.golden | 5 + .../false_bool_pointer/marshaled_json.golden | 1 + .../full_struct/marshaled_json.golden | 9 + .../int_pointer/marshaled_json.golden | 1 + .../partial_struct/marshaled_json.golden | 4 + .../string_pointer/marshaled_json.golden | 1 + .../true_bool_pointer/marshaled_json.golden | 1 + .../custom_marshaling/marshaled_xml.golden | 1 + .../empty_struct/marshaled_xml.golden | 4 + .../false_bool_pointer/marshaled_xml.golden | 1 + .../full_struct/marshaled_xml.golden | 9 + .../int_pointer/marshaled_xml.golden | 1 + .../partial_struct/marshaled_xml.golden | 4 + .../string_pointer/marshaled_xml.golden | 1 + .../true_bool_pointer/marshaled_xml.golden | 1 + .../custom_marshaling/marshaled_xml.golden | 1 + .../empty_struct/marshaled_xml.golden | 4 + .../false_bool_pointer/marshaled_xml.golden | 1 + .../full_struct/marshaled_xml.golden | 9 + .../int_pointer/marshaled_xml.golden | 1 + .../partial_struct/marshaled_xml.golden | 4 + .../string_pointer/marshaled_xml.golden | 1 + .../true_bool_pointer/marshaled_xml.golden | 1 + .../custom_marshaling/marshaled_yaml.golden | 2 + .../empty_struct/marshaled_yaml.golden | 2 + .../false_bool_pointer/marshaled_yaml.golden | 1 + .../full_struct/marshaled_yaml.golden | 6 + .../int_pointer/marshaled_yaml.golden | 1 + .../partial_struct/marshaled_yaml.golden | 2 + .../string_pointer/marshaled_yaml.golden | 1 + .../true_bool_pointer/marshaled_yaml.golden | 1 + .../custom_marshaling/marshaled_yaml.golden | 2 + .../empty_struct/marshaled_yaml.golden | 3 + .../false_bool_pointer/marshaled_yaml.golden | 1 + .../full_struct/marshaled_yaml.golden | 6 + .../int_pointer/marshaled_yaml.golden | 1 + .../partial_struct/marshaled_yaml.golden | 2 + .../string_pointer/marshaled_yaml.golden | 1 + .../true_bool_pointer/marshaled_yaml.golden | 1 + .../custom_marshaling/marshaled_json.golden | 3 + .../empty_struct/marshaled_json.golden | 4 + .../false_bool_pointer/marshaled_json.golden | 1 + .../full_struct/marshaled_json.golden | 9 + .../int_pointer/marshaled_json.golden | 1 + .../partial_struct/marshaled_json.golden | 4 + .../string_pointer/marshaled_json.golden | 1 + .../true_bool_pointer/marshaled_json.golden | 1 + .../custom_marshaling/marshaled_json.golden | 3 + .../empty_struct/marshaled_json.golden | 5 + .../false_bool_pointer/marshaled_json.golden | 1 + .../full_struct/marshaled_json.golden | 9 + .../int_pointer/marshaled_json.golden | 1 + .../partial_struct/marshaled_json.golden | 4 + .../string_pointer/marshaled_json.golden | 1 + .../true_bool_pointer/marshaled_json.golden | 1 + .../custom_marshaling/marshaled_xml.golden | 1 + .../empty_struct/marshaled_xml.golden | 4 + .../false_bool_pointer/marshaled_xml.golden | 1 + .../full_struct/marshaled_xml.golden | 9 + .../int_pointer/marshaled_xml.golden | 1 + .../partial_struct/marshaled_xml.golden | 4 + .../string_pointer/marshaled_xml.golden | 1 + .../true_bool_pointer/marshaled_xml.golden | 1 + .../custom_marshaling/marshaled_xml.golden | 1 + .../empty_struct/marshaled_xml.golden | 4 + .../false_bool_pointer/marshaled_xml.golden | 1 + .../full_struct/marshaled_xml.golden | 9 + .../int_pointer/marshaled_xml.golden | 1 + .../partial_struct/marshaled_xml.golden | 4 + .../string_pointer/marshaled_xml.golden | 1 + .../true_bool_pointer/marshaled_xml.golden | 1 + .../custom_marshaling/marshaled_yaml.golden | 2 + .../empty_struct/marshaled_yaml.golden | 2 + .../false_bool_pointer/marshaled_yaml.golden | 1 + .../full_struct/marshaled_yaml.golden | 6 + .../int_pointer/marshaled_yaml.golden | 1 + .../partial_struct/marshaled_yaml.golden | 2 + .../string_pointer/marshaled_yaml.golden | 1 + .../true_bool_pointer/marshaled_yaml.golden | 1 + .../custom_marshaling/marshaled_yaml.golden | 2 + .../empty_struct/marshaled_yaml.golden | 3 + .../false_bool_pointer/marshaled_yaml.golden | 1 + .../full_struct/marshaled_yaml.golden | 6 + .../int_pointer/marshaled_yaml.golden | 1 + .../partial_struct/marshaled_yaml.golden | 2 + .../string_pointer/marshaled_yaml.golden | 1 + .../true_bool_pointer/marshaled_yaml.golden | 1 + .../marshaled_json.golden | 3 + .../marshaled_xml.golden | 3 + .../marshaled_yaml.golden | 1 + .../marshaled_json.golden | 3 + .../marshaled_xml.golden | 3 + .../marshaled_yaml.golden | 1 + .../empty/marshaled_json.golden | 1 + .../empty/marshaled_xml.golden | 1 + .../empty/marshaled_yaml.golden | 1 + .../full/marshaled_json.golden | 3 + .../full/marshaled_xml.golden | 3 + .../full/marshaled_yaml.golden | 1 + update.go | 7 +- 118 files changed, 1248 insertions(+), 17 deletions(-) create mode 100644 assert.go create mode 100644 assert_example_test.go create mode 100644 assert_test.go rename example_test.go => golden_example_test.go (100%) create mode 100644 marshal_asserter.go create mode 100644 testdata/TestAssertJSONMarshaling/custom_marshaling/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshaling/empty_struct/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshaling/false_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshaling/full_struct/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshaling/int_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshaling/partial_struct/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshaling/string_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshaling/true_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/custom_marshaling/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/empty_struct/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/false_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/full_struct/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/int_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/partial_struct/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/string_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertJSONMarshalingP/true_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssertXMLMarshaling/custom_marshaling/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshaling/empty_struct/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshaling/false_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshaling/full_struct/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshaling/int_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshaling/partial_struct/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshaling/string_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshaling/true_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/custom_marshaling/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/empty_struct/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/false_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/full_struct/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/int_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/partial_struct/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/string_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertXMLMarshalingP/true_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/custom_marshaling/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/empty_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/false_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/full_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/int_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/partial_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/string_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshaling/true_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/custom_marshaling/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/empty_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/full_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/int_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/partial_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/string_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssertYAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_JSONMarshaling/custom_marshaling/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshaling/empty_struct/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshaling/false_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshaling/full_struct/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshaling/int_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshaling/partial_struct/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshaling/string_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshaling/true_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/custom_marshaling/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/empty_struct/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/false_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/full_struct/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/int_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/partial_struct/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/string_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_JSONMarshalingP/true_bool_pointer/marshaled_json.golden create mode 100644 testdata/TestAssert_XMLMarshaling/custom_marshaling/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshaling/empty_struct/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshaling/false_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshaling/full_struct/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshaling/int_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshaling/partial_struct/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshaling/string_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshaling/true_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/custom_marshaling/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/empty_struct/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/false_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/full_struct/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/int_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/partial_struct/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/string_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_XMLMarshalingP/true_bool_pointer/marshaled_xml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/custom_marshaling/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/empty_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/false_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/full_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/int_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/partial_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/string_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshaling/true_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/custom_marshaling/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/empty_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/full_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/int_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/partial_struct/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/string_pointer/marshaled_yaml.golden create mode 100644 testdata/TestAssert_YAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden create mode 100644 testdata/TestExampleMyBookMarshaling/marshaled_json.golden create mode 100644 testdata/TestExampleMyBookMarshaling/marshaled_xml.golden create mode 100644 testdata/TestExampleMyBookMarshaling/marshaled_yaml.golden create mode 100644 testdata/TestExampleMyBookMarshalingP/marshaled_json.golden create mode 100644 testdata/TestExampleMyBookMarshalingP/marshaled_xml.golden create mode 100644 testdata/TestExampleMyBookMarshalingP/marshaled_yaml.golden create mode 100644 testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_json.golden create mode 100644 testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_xml.golden create mode 100644 testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_yaml.golden create mode 100644 testdata/TestExampleMyBookMarshalingTabular/full/marshaled_json.golden create mode 100644 testdata/TestExampleMyBookMarshalingTabular/full/marshaled_xml.golden create mode 100644 testdata/TestExampleMyBookMarshalingTabular/full/marshaled_yaml.golden diff --git a/.gitignore b/.gitignore index f65385f..98d92b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ bin/* coverage.out -testdata/* -!testdata/TestExample* +testdata/TestFile* +testdata/TestGet* +testdata/TestSet* diff --git a/assert.go b/assert.go new file mode 100644 index 0000000..b18033d --- /dev/null +++ b/assert.go @@ -0,0 +1,307 @@ +package golden + +import ( + "bytes" + "encoding/json" + "encoding/xml" + "io" + "testing" + + "gopkg.in/yaml.v3" +) + +var globalAssert = NewAssert() + +// AssertJSONMarshaling asserts that the given "v" value JSON marshals to an +// expected value fetched from a golden file on disk, and then verifies that the +// marshaled result produces a value that is equal to "v" when unmarshaled. +// +// Used for objects that do NOT change when they are marshaled and unmarshaled. +func AssertJSONMarshaling(t *testing.T, v interface{}) { + t.Helper() + + globalAssert.JSONMarshaling(t, v) +} + +// AssertJSONMarshalingP asserts that the given "v" value JSON marshals to an +// expected value fetched from a golden file on disk, and then verifies that the +// marshaled result produces a value that is equal to "want" when unmarshaled. +// +// Used for objects that change when they are marshaled and unmarshaled. +func AssertJSONMarshalingP(t *testing.T, v, want interface{}) { + t.Helper() + + globalAssert.JSONMarshalingP(t, v, want) +} + +// AssertXMLMarshaling asserts that the given "v" value XML marshals to an +// expected value fetched from a golden file on disk, and then verifies that the +// marshaled result produces a value that is equal to "v" when unmarshaled. +// +// Used for objects that do NOT change when they are marshaled and unmarshaled. +func AssertXMLMarshaling(t *testing.T, v interface{}) { + t.Helper() + + globalAssert.XMLMarshaling(t, v) +} + +// AssertXMLMarshalingP asserts that the given "v" value XML marshals to an +// expected value fetched from a golden file on disk, and then verifies that the +// marshaled result produces a value that is equal to "want" when unmarshaled. +// +// Used for objects that change when they are marshaled and unmarshaled. +func AssertXMLMarshalingP(t *testing.T, v, want interface{}) { + t.Helper() + + globalAssert.XMLMarshalingP(t, v, want) +} + +// AssertYAMLMarshaling asserts that the given "v" value YAML marshals to an +// expected value fetched from a golden file on disk, and then verifies that the +// marshaled result produces a value that is equal to "v" when unmarshaled. +// +// Used for objects that do NOT change when they are marshaled and unmarshaled. +func AssertYAMLMarshaling(t *testing.T, v interface{}) { + t.Helper() + + globalAssert.YAMLMarshaling(t, v) +} + +// AssertYAMLMarshalingP asserts that the given "v" value YAML marshals to an +// expected value fetched from a golden file on disk, and then verifies that the +// marshaled result produces a value that is equal to "want" when unmarshaled. +// +// Used for objects that change when they are marshaled and unmarshaled. +func AssertYAMLMarshalingP(t *testing.T, v, want interface{}) { + t.Helper() + + globalAssert.YAMLMarshalingP(t, v, want) +} + +// Assert exposes a series of JSON, YAML, and XML marshaling assertion helpers. +type Assert interface { + // JSONMarshaling asserts that the given "v" value JSON marshals to an + // expected value fetched from a golden file on disk, and then verifies that + // the marshaled result produces a value that is equal to "v" when + // unmarshaled. + // + // Used for objects that do NOT change when they are marshaled and + // unmarshaled. + JSONMarshaling(t *testing.T, v interface{}) + + // JSONMarshalingP asserts that the given "v" value JSON marshals to an + // expected value fetched from a golden file on disk, and then verifies that + // the marshaled result produces a value that is equal to "want" when + // unmarshaled. + // + // Used for objects that change when they are marshaled and unmarshaled. + JSONMarshalingP(t *testing.T, v interface{}, want interface{}) + + // XMLMarshaling asserts that the given "v" value XML marshals to an + // expected value fetched from a golden file on disk, and then verifies that + // the marshaled result produces a value that is equal to "v" when + // unmarshaled. + // + // Used for objects that do NOT change when they are marshaled and + // unmarshaled. + XMLMarshaling(t *testing.T, v interface{}) + + // XMLMarshalingP asserts that the given "v" value XML marshals to an + // expected value fetched from a golden file on disk, and then verifies that + // the marshaled result produces a value that is equal to "want" when + // unmarshaled. + // + // Used for objects that change when they are marshaled and unmarshaled. + XMLMarshalingP(t *testing.T, v interface{}, want interface{}) + + // YAMLMarshaling asserts that the given "v" value YAML marshals to an + // expected value fetched from a golden file on disk, and then verifies that + // the marshaled result produces a value that is equal to "v" when + // unmarshaled. + // + // Used for objects that do NOT change when they are marshaled and + // unmarshaled. + YAMLMarshaling(t *testing.T, v interface{}) + + // YAMLMarshalingP asserts that the given "v" value YAML marshals to an + // expected value fetched from a golden file on disk, and then verifies that + // the marshaled result produces a value that is equal to "want" when + // unmarshaled. + // + // Used for objects that change when they are marshaled and unmarshaled. + YAMLMarshalingP(t *testing.T, v interface{}, want interface{}) +} + +type AssertOption interface { + apply(*asserter) +} + +type assertOptionFunc func(*asserter) + +func (fn assertOptionFunc) apply(c *asserter) { + fn(c) +} + +// WithGolden allows setting a custom *Golden instance when calling NewAssert(). +func WithGolden(golden *Golden) AssertOption { + return assertOptionFunc(func(a *asserter) { + a.golden = golden + }) +} + +// WithNormalizedLineBreaks allows turning off line-break normalization which +// replaces Windows' CRLF (\r\n) and Mac Classic CR (\r) line breaks with Unix's +// LF (\n) line breaks. +func WithNormalizedLineBreaks(value bool) AssertOption { + return assertOptionFunc(func(a *asserter) { + a.normalizeLineBreaks = value + }) +} + +// NewAssert returns a new Assert which exposes a number of marshaling assertion +// helpers for JSON, YAML and XML. +// +// The default encoders all specify indentation of two spaces, essentially +// enforcing pretty formatting for JSON and XML. +// +// The default decoders for JSON and YAML prohibit unknown fields which are not +// present on the provided struct. +func NewAssert(options ...AssertOption) Assert { + a := &asserter{ + golden: globalGolden, + normalizeLineBreaks: true, + } + + for _, opt := range options { + opt.apply(a) + } + + a.JSONAsserter = NewMarshalAsserter( + a.golden, "JSON", + newJSONEncoder, newJSONDecoder, + a.normalizeLineBreaks, + ) + a.XMLAsserter = NewMarshalAsserter( + a.golden, "XML", + newXMLEncoder, newXMLDecoder, + a.normalizeLineBreaks, + ) + a.YAMLAsserter = NewMarshalAsserter( + a.golden, "YAML", + newYAMLEncoder, newYAMLDecoder, + a.normalizeLineBreaks, + ) + + return a +} + +// asserter implements the Assert interface. +type asserter struct { + golden *Golden + normalizeLineBreaks bool + + JSONAsserter *MarshalAsserter + XMLAsserter *MarshalAsserter + YAMLAsserter *MarshalAsserter +} + +func (s *asserter) JSONMarshaling(t *testing.T, v interface{}) { + t.Helper() + + s.JSONAsserter.Marshaling(t, v) +} + +func (s *asserter) JSONMarshalingP( + t *testing.T, + v interface{}, + want interface{}, +) { + t.Helper() + + s.JSONAsserter.MarshalingP(t, v, want) +} + +func (s *asserter) XMLMarshaling(t *testing.T, v interface{}) { + t.Helper() + + s.XMLAsserter.Marshaling(t, v) +} + +func (s *asserter) XMLMarshalingP(t *testing.T, v, want interface{}) { + t.Helper() + + s.XMLAsserter.MarshalingP(t, v, want) +} + +func (s *asserter) YAMLMarshaling(t *testing.T, v interface{}) { + t.Helper() + + s.YAMLAsserter.Marshaling(t, v) +} + +func (s *asserter) YAMLMarshalingP(t *testing.T, v, want interface{}) { + t.Helper() + + s.YAMLAsserter.MarshalingP(t, v, want) +} + +// newJSONEncoder is the default JSONEncoderFunc used by Assert. It returns a +// *json.Encoder which is set to indent with two spaces. +func newJSONEncoder(w io.Writer) MarshalEncoder { + enc := json.NewEncoder(w) + enc.SetIndent("", " ") + + return enc +} + +// newJSONDecoder is the default JSONDecoderFunc used by Assert. It returns a +// *json.Decoder which disallows unknown fields. +func newJSONDecoder(r io.Reader) MarshalDecoder { + dec := json.NewDecoder(r) + dec.DisallowUnknownFields() + + return dec +} + +// newXMLEncoder is the default XMLEncoderFunc used by Assert. It returns a +// *xml.Encoder which is set to indent with two spaces. +func newXMLEncoder(w io.Writer) MarshalEncoder { + enc := xml.NewEncoder(w) + enc.Indent("", " ") + + return enc +} + +// newXMLDecoder is the default XMLDecoderFunc used by Assert. +func newXMLDecoder(r io.Reader) MarshalDecoder { + return xml.NewDecoder(r) +} + +// newYAMLEncoder is the default YAMLEncoderFunc used by Assert. It returns a +// *yaml.Encoder which is set to indent with two spaces. +func newYAMLEncoder(w io.Writer) MarshalEncoder { + enc := yaml.NewEncoder(w) + enc.SetIndent(2) + + return enc +} + +// newYAMLDecoder is the default YAMLDecoderFunc used by Assert. It returns a +// *yaml.Decoder which disallows unknown fields. +func newYAMLDecoder(r io.Reader) MarshalDecoder { + dec := yaml.NewDecoder(r) + dec.KnownFields(true) + + return dec +} + +// normalizeLineBreaks replaces Windows CRLF (\r\n) and Classic MacOS CR (\r) +// line-breaks with Unix LF (\n) line breaks. +func normalizeLineBreaks(data []byte) []byte { + // Replace Windows CRLF (\r\n) with Unix LF (\n) + result := bytes.ReplaceAll(data, []byte{13, 10}, []byte{10}) + // Replace Classic MacOS CR (\r) with Unix LF (\n) + result = bytes.ReplaceAll(result, []byte{13}, []byte{10}) + + return result +} diff --git a/assert_example_test.go b/assert_example_test.go new file mode 100644 index 0000000..ef660da --- /dev/null +++ b/assert_example_test.go @@ -0,0 +1,68 @@ +package golden_test + +import ( + "testing" + + "github.com/jimeh/go-golden" +) + +type MyBook struct { + FooBar string `json:"foo_bar,omitempty" yaml:"fooBar,omitempty" xml:"Foo_Bar,omitempty"` + Bar string `json:"-" yaml:"-" xml:"-"` + baz string +} + +// TestExampleMyBookMarshaling reads/writes the following golden files: +// +// testdata/TestExampleMyBookMarshaling/marshaled_json.golden +// testdata/TestExampleMyBookMarshaling/marshaled_xml.golden +// testdata/TestExampleMyBookMarshaling/marshaled_yaml.golden +// +func TestExampleMyBookMarshaling(t *testing.T) { + obj := &MyBook{FooBar: "Hello World!"} + + golden.AssertJSONMarshaling(t, obj) + golden.AssertYAMLMarshaling(t, obj) + golden.AssertXMLMarshaling(t, obj) +} + +// TestExampleMyBookMarshalingP reads/writes the following golden files: +// +// testdata/TestExampleMyBookMarshalingP/marshaled_json.golden +// testdata/TestExampleMyBookMarshalingP/marshaled_xml.golden +// testdata/TestExampleMyBookMarshalingP/marshaled_yaml.golden +// +func TestExampleMyBookMarshalingP(t *testing.T) { + obj := &MyBook{FooBar: "Hello World!", Bar: "Oops", baz: "nope!"} + want := &MyBook{FooBar: "Hello World!"} + + golden.AssertJSONMarshalingP(t, obj, want) + golden.AssertYAMLMarshalingP(t, obj, want) + golden.AssertXMLMarshalingP(t, obj, want) +} + +// TestExampleMyBookMarshalingTabular reads/writes the following golden files: +// +// testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_json.golden +// testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_xml.golden +// testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_yaml.golden +// testdata/TestExampleMyBookMarshalingTabular/full/marshaled_json.golden +// testdata/TestExampleMyBookMarshalingTabular/full/marshaled_xml.golden +// testdata/TestExampleMyBookMarshalingTabular/full/marshaled_yaml.golden +// +func TestExampleMyBookMarshalingTabular(t *testing.T) { + tests := []struct { + name string + obj *MyBook + }{ + {name: "empty", obj: &MyBook{}}, + {name: "full", obj: &MyBook{FooBar: "Hello World!"}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + golden.AssertJSONMarshaling(t, tt.obj) + golden.AssertYAMLMarshaling(t, tt.obj) + golden.AssertXMLMarshaling(t, tt.obj) + }) + } +} diff --git a/assert_test.go b/assert_test.go new file mode 100644 index 0000000..c88f7a6 --- /dev/null +++ b/assert_test.go @@ -0,0 +1,370 @@ +package golden + +import ( + "bytes" + "encoding/xml" + "fmt" + "regexp" + "testing" + "time" + + "gopkg.in/yaml.v3" +) + +// +// Helpers +// + +type Author struct { + FirstName string `json:"first_name" yaml:"first_name" xml:"first_name"` + LastName string `json:"last_name" yaml:"last_name" xml:"last_name"` +} + +type Book struct { + ID string `json:"id" yaml:"id" xml:"id"` + Title string `json:"title" yaml:"title" xml:"title"` + Author *Author `json:"author,omitempty" yaml:"author,omitempty" xml:"author,omitempty"` + Year int `json:"year,omitempty" yaml:"year,omitempty" xml:"year,omitempty"` +} + +type Article struct { + ID string `json:"id" yaml:"id" xml:"id"` + Title string `json:"title" yaml:"title" xml:"title"` + Author *Author `json:"author" yaml:"author" xml:"author"` + Date *time.Time `json:"date,omitempty" yaml:"date,omitempty" xml:"date,omitempty"` + + Rank int `json:"-" yaml:"-" xml:"-"` + order int +} + +type Comic struct { + ID string + Name string + Issue string + Ignored string +} + +type xmlComic struct { + ID string `xml:"id,attr"` + Name string `xml:",chardata"` + Issue string `xml:"issue,attr"` +} + +func (s *Comic) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`{"%s":"%s=%s"}`, s.ID, s.Name, s.Issue)), nil +} + +func (s *Comic) UnmarshalJSON(data []byte) error { + m := regexp.MustCompile(`^{\s*"(.*?)":\s*"(.*?)=(.*)"\s*}$`) + matches := m.FindSubmatch(bytes.TrimSpace(data)) + if matches == nil { + return nil + } + + s.ID = string(matches[1]) + s.Name = string(matches[2]) + s.Issue = string(matches[3]) + + return nil +} + +func (s *Comic) MarshalYAML() (interface{}, error) { + return map[string]map[string]string{s.ID: {s.Name: s.Issue}}, nil +} + +func (s *Comic) UnmarshalYAML(value *yaml.Node) error { + // Horribly hacky code, but it works and specifically only needs to extract + // these specific three values. + if len(value.Content) == 2 { + s.ID = value.Content[0].Value + if len(value.Content[1].Content) == 2 { + s.Name = value.Content[1].Content[0].Value + s.Issue = value.Content[1].Content[1].Value + } + } + + return nil +} + +func (s *Comic) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + return e.EncodeElement( + &xmlComic{ID: s.ID, Name: s.Name, Issue: s.Issue}, + start, + ) +} + +func (s *Comic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + x := &xmlComic{} + _ = d.DecodeElement(x, &start) + + v := Comic{ID: x.ID, Name: x.Name, Issue: x.Issue} + + *s = v + + return nil +} + +func boolPtr(b bool) *bool { + return &b +} + +func intPtr(i int) *int { + return &i +} + +func stringPtr(s string) *string { + return &s +} + +// +// Test cases +// + +var marhalingTestCases = []struct { + name string + v interface{} +}{ + { + name: "true bool pointer", + v: boolPtr(true), + }, + { + name: "false bool pointer", + v: boolPtr(false), + }, + { + name: "int pointer", + v: intPtr(42), + }, + { + name: "string pointer", + v: stringPtr("hello world"), + }, + { + name: "empty struct", + v: &Book{}, + }, + { + name: "partial struct", + v: &Book{ + ID: "cfda163c-d5c1-44a2-909b-5d2ce3a31979", + Title: "The Traveler", + }, + }, + { + name: "full struct", + v: &Book{ + ID: "cfda163c-d5c1-44a2-909b-5d2ce3a31979", + Title: "The Traveler", + Author: &Author{ + FirstName: "John", + LastName: "Twelve Hawks", + }, + Year: 2005, + }, + }, + { + name: "custom marshaling", + v: &Comic{ + ID: "2fd5af35-b85e-4f03-8eba-524be28d7a5b", + Name: "Hello World!", + Issue: "Forty Two", + }, + }, +} + +var articleDate = time.Date( + 2021, time.October, 27, 23, 30, 34, 0, time.FixedZone("", 1*60*60), +).UTC() + +var marshalingPTestCases = []struct { + name string + v interface{} + want interface{} +}{ + { + name: "true bool pointer", + v: boolPtr(true), + want: boolPtr(true), + }, + { + name: "false bool pointer", + v: boolPtr(false), + want: boolPtr(false), + }, + { + name: "int pointer", + v: intPtr(42), + want: intPtr(42), + }, + { + name: "string pointer", + v: stringPtr("hello world"), + want: stringPtr("hello world"), + }, + { + name: "empty struct", + v: &Article{}, + want: &Article{}, + }, + { + name: "partial struct", + v: &Book{ + ID: "10eec54d-e30a-4428-be18-01095d889126", + Title: "Time Travel", + }, + want: &Book{ + ID: "10eec54d-e30a-4428-be18-01095d889126", + Title: "Time Travel", + }, + }, + { + name: "full struct", + v: &Article{ + ID: "10eec54d-e30a-4428-be18-01095d889126", + Title: "Time Travel", + Author: &Author{ + FirstName: "Doc", + LastName: "Brown", + }, + Date: &articleDate, + Rank: 8, + order: 16, + }, + want: &Article{ + ID: "10eec54d-e30a-4428-be18-01095d889126", + Title: "Time Travel", + Author: &Author{ + FirstName: "Doc", + LastName: "Brown", + }, + Date: &articleDate, + }, + }, + { + name: "custom marshaling", + v: &Comic{ + ID: "2fd5af35-b85e-4f03-8eba-524be28d7a5b", + Name: "Hello World!", + Issue: "Forty Two", + Ignored: "don't pay attention to this :)", + }, + want: &Comic{ + ID: "2fd5af35-b85e-4f03-8eba-524be28d7a5b", + Name: "Hello World!", + Issue: "Forty Two", + }, + }, +} + +// +// Tests +// + +func TestAssertJSONMarshaling(t *testing.T) { + for _, tt := range marhalingTestCases { + t.Run(tt.name, func(t *testing.T) { + AssertJSONMarshaling(t, tt.v) + }) + } +} + +func TestAssertJSONMarshalingP(t *testing.T) { + for _, tt := range marshalingPTestCases { + t.Run(tt.name, func(t *testing.T) { + AssertJSONMarshalingP(t, tt.v, tt.want) + }) + } +} + +func TestAssertXMLMarshaling(t *testing.T) { + for _, tt := range marhalingTestCases { + t.Run(tt.name, func(t *testing.T) { + AssertXMLMarshaling(t, tt.v) + }) + } +} + +func TestAssertXMLMarshalingP(t *testing.T) { + for _, tt := range marshalingPTestCases { + t.Run(tt.name, func(t *testing.T) { + AssertXMLMarshalingP(t, tt.v, tt.want) + }) + } +} + +func TestAssertYAMLMarshaling(t *testing.T) { + for _, tt := range marhalingTestCases { + t.Run(tt.name, func(t *testing.T) { + AssertYAMLMarshaling(t, tt.v) + }) + } +} + +func TestAssertYAMLMarshalingP(t *testing.T) { + for _, tt := range marshalingPTestCases { + t.Run(tt.name, func(t *testing.T) { + AssertYAMLMarshalingP(t, tt.v, tt.want) + }) + } +} + +func TestAssert_JSONMarshaling(t *testing.T) { + for _, tt := range marhalingTestCases { + t.Run(tt.name, func(t *testing.T) { + assert := NewAssert() + + assert.JSONMarshaling(t, tt.v) + }) + } +} + +func TestAssert_JSONMarshalingP(t *testing.T) { + for _, tt := range marshalingPTestCases { + t.Run(tt.name, func(t *testing.T) { + assert := NewAssert() + + assert.JSONMarshalingP(t, tt.v, tt.want) + }) + } +} + +func TestAssert_XMLMarshaling(t *testing.T) { + for _, tt := range marhalingTestCases { + t.Run(tt.name, func(t *testing.T) { + assert := NewAssert() + + assert.XMLMarshaling(t, tt.v) + }) + } +} + +func TestAssert_XMLMarshalingP(t *testing.T) { + for _, tt := range marshalingPTestCases { + t.Run(tt.name, func(t *testing.T) { + assert := NewAssert() + + assert.XMLMarshalingP(t, tt.v, tt.want) + }) + } +} + +func TestAssert_YAMLMarshaling(t *testing.T) { + for _, tt := range marhalingTestCases { + t.Run(tt.name, func(t *testing.T) { + assert := NewAssert() + + assert.YAMLMarshaling(t, tt.v) + }) + } +} + +func TestAssert_YAMLMarshalingP(t *testing.T) { + for _, tt := range marshalingPTestCases { + t.Run(tt.name, func(t *testing.T) { + assert := NewAssert() + + assert.YAMLMarshalingP(t, tt.v, tt.want) + }) + } +} diff --git a/go.mod b/go.mod index 6182b53..61c8115 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ go 1.15 require ( github.com/jimeh/envctl v0.1.0 github.com/stretchr/testify v1.7.0 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) diff --git a/go.sum b/go.sum index 341eccf..078e210 100644 --- a/go.sum +++ b/go.sum @@ -10,5 +10,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/golden.go b/golden.go index 948d369..40e62a6 100644 --- a/golden.go +++ b/golden.go @@ -1,14 +1,67 @@ // Package golden is yet another package for working with *.golden test files, -// with a focus on simplicity through it's default behavior. +// with a focus on simplicity through it's default behavior, and marshaling +// assertion helpers to validate JSON/YAML/XML format of structs. // // Golden file names are based on the name of the test function and any subtest // names by calling t.Name(). File names are sanitized to ensure they're -// compatible with Linux, macOS and Windows systems regardless of what crazy +// compatible with Linux, macOS and Windows systems regardless of what // characters might be in a subtest's name. // -// Usage +// Assertion Helpers // -// Typical usage should look something like this: +// There are marshaling assertion helpers for JSON, YAML, and XML. Each helper +// operates in two stages: +// +// 1. Marshal the provided object to a byte slice and read the corresponding +// golden file from disk followed by verifying both are identical. +// +// 2. Unmarshal the content of the golden file, verifying that the result is +// identical to the original given object. +// +// Typical usage of a assertion helper would look something like this in a +// tabular test: +// +// type MyStruct struct { +// FooBar string `json:"foo_bar" yaml:"fooBar" xml:"Foo_Bar"` +// } +// +// func TestMyStructMarshaling(t *testing.T) { +// tests := []struct { +// name string +// obj *MyStruct +// }{ +// {name: "empty", obj: &MyStruct{}}, +// {name: "full", obj: &MyStruct{FooBar: "Hello World!"}}, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// golden.AssertJSONMarshaling(t, tt.obj) +// golden.AssertYAMLMarshaling(t, tt.obj) +// golden.AssertXMLMarshaling(t, tt.obj) +// }) +// } +// } +// +// The above example will read from the following golden files: +// +// testdata/TestMyStructMarshaling/empty/marshaled_json.golden +// testdata/TestMyStructMarshaling/empty/marshaled_xml.golden +// testdata/TestMyStructMarshaling/empty/marshaled_yaml.golden +// testdata/TestMyStructMarshaling/full/marshaled_json.golden +// testdata/TestMyStructMarshaling/full/marshaled_xml.golden +// testdata/TestMyStructMarshaling/full/marshaled_yaml.golden +// +// If a corresponding golden file cannot be found on disk, the test will fail. +// To create/update golden files, simply set the GOLDEN_UPDATE environment +// variable to one of "1", "y", "t", "yes", "on", or "true" when running the +// tests. +// +// Golden files should be committed to source control, as it allow tests to fail +// when the marshaling results for an object changes. +// +// Golden Usage +// +// Typical usage would look something like this: // // func TestExampleMyStruct(t *testing.T) { // got, err := json.Marshal(&MyStruct{Foo: "Bar"}) @@ -139,14 +192,14 @@ const ( var DefaultUpdateFunc = EnvUpdateFunc -var global = New() +var globalGolden = New() // File returns the filename of the golden file for the given *testing.T // instance as determined by t.Name(). func File(t *testing.T) string { t.Helper() - return global.File(t) + return globalGolden.File(t) } // Get returns the content of the golden file for the given *testing.T instance @@ -155,7 +208,7 @@ func File(t *testing.T) string { func Get(t *testing.T) []byte { t.Helper() - return global.Get(t) + return globalGolden.Get(t) } // Set writes given data to the golden file for the given *testing.T instance as @@ -164,7 +217,7 @@ func Get(t *testing.T) []byte { func Set(t *testing.T, data []byte) { t.Helper() - global.Set(t, data) + globalGolden.Set(t, data) } // FileP returns the filename of the specifically named golden file for the @@ -172,7 +225,7 @@ func Set(t *testing.T, data []byte) { func FileP(t *testing.T, name string) string { t.Helper() - return global.FileP(t, name) + return globalGolden.FileP(t, name) } // GetP returns the content of the specifically named golden file belonging @@ -184,7 +237,7 @@ func FileP(t *testing.T, name string) string { func GetP(t *testing.T, name string) []byte { t.Helper() - return global.GetP(t, name) + return globalGolden.GetP(t, name) } // SetP writes given data of the specifically named golden file belonging to @@ -196,7 +249,7 @@ func GetP(t *testing.T, name string) []byte { func SetP(t *testing.T, name string, data []byte) { t.Helper() - global.SetP(t, name, data) + globalGolden.SetP(t, name, data) } // Update returns true when golden is set to update golden files. Should be used @@ -206,7 +259,7 @@ func SetP(t *testing.T, name string, data []byte) { // environment variable is set to a truthy value. To customize create a custom // *Golden instance with New() and set a new UpdateFunc value. func Update() bool { - return global.Update() + return globalGolden.Update() } // Golden handles all interactions with golden files. The top-level package diff --git a/example_test.go b/golden_example_test.go similarity index 100% rename from example_test.go rename to golden_example_test.go diff --git a/marshal_asserter.go b/marshal_asserter.go new file mode 100644 index 0000000..f5ae6b2 --- /dev/null +++ b/marshal_asserter.go @@ -0,0 +1,151 @@ +package golden + +import ( + "bytes" + "io" + "reflect" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type ( + NewEncoderFunc func(w io.Writer) MarshalEncoder + NewDecoderFunc func(r io.Reader) MarshalDecoder +) + +type MarshalEncoder interface { + Encode(v interface{}) error +} + +type MarshalDecoder interface { + Decode(v interface{}) error +} + +// MarshalAsserter allows building custom marshaling asserters, but providing +// functions which returns new encoder and decoders for the format to be +// asserted. +// +// All the AssertMarshaling helper functions uses MarshalAsserter under +// the hood. +type MarshalAsserter struct { + // Golden is the *Golden instance used to read/write golden files. + Golden *Golden + + // Name of the format the MarshalAsserter handles. + Format string + + // GoldName is the name of the golden file used when marshaling. This is by + // default set based on Format using NewMarshalAsserter. For example if + // Format is set to "JSON", GoldName will be set to "marshaled_json" by + // default. + GoldName string + + // NewEncoderFunc is the function used to create a new encoder for + // marshaling objects. + NewEncoderFunc NewEncoderFunc + + // NewDecoderFunc is the function used to create a new decoder for + // unmarshaling objects. + NewDecoderFunc NewDecoderFunc + + // NormalizeLineBreaks determines if Windows' CRLF (\r\n) and Mac Classic CR + // (\r) line breaks are replaced with Unix's LF (\n) line breaks. This + // ensure marshaling assertions works cross platform. + NormalizeLineBreaks bool +} + +func NewMarshalAsserter( + golden *Golden, + format string, + newEncoderFunc NewEncoderFunc, + newDecoderFunc NewDecoderFunc, + normalizeLineBreaks bool, +) *MarshalAsserter { + if golden == nil { + golden = globalGolden + } + + goldName := "marshaled_" + strings.ToLower(sanitizeFilename(format)) + + return &MarshalAsserter{ + Golden: golden, + Format: format, + GoldName: goldName, + NewEncoderFunc: newEncoderFunc, + NewDecoderFunc: newDecoderFunc, + NormalizeLineBreaks: normalizeLineBreaks, + } +} + +// Marshaling asserts that the given "v" value marshals via the provided encoder +// to an expected value fetched from a golden file on disk, and then verifies +// that the marshaled result produces a value that is equal to "v" when +// unmarshaled. +// +// Used for objects that do NOT change when they are marshaled and unmarshaled. +func (s *MarshalAsserter) Marshaling(t *testing.T, v interface{}) { + t.Helper() + + s.MarshalingP(t, v, v) +} + +// MarshalingP asserts that the given "v" value marshals via the provided +// encoder to an expected value fetched from a golden file on disk, and then +// verifies that the marshaled result produces a value that is equal to "want" +// when unmarshaled. +// +// Used for objects that change when they are marshaled and unmarshaled. +func (s *MarshalAsserter) MarshalingP( + t *testing.T, + v interface{}, + want interface{}, +) { + t.Helper() + + if reflect.ValueOf(want).Kind() != reflect.Ptr { + require.FailNowf(t, + "only pointer types can be asserted", + "%T is not a pointer type", want, + ) + } + + var buf bytes.Buffer + err := s.NewEncoderFunc(&buf).Encode(v) + require.NoErrorf(t, err, "failed to %s marshal %T: %+v", s.Format, v, v) + + marshaled := buf.Bytes() + if s.NormalizeLineBreaks { + marshaled = normalizeLineBreaks(marshaled) + } + + if s.Golden.Update() { + s.Golden.SetP(t, s.GoldName, marshaled) + } + + gold := s.Golden.GetP(t, s.GoldName) + if s.NormalizeLineBreaks { + gold = normalizeLineBreaks(gold) + } + + switch strings.ToLower(s.Format) { + case "json": + assert.JSONEq(t, string(gold), string(marshaled)) + case "yaml", "yml": + assert.YAMLEq(t, string(gold), string(marshaled)) + default: + assert.Equal(t, string(gold), string(marshaled)) + } + + got := reflect.New(reflect.TypeOf(want).Elem()).Interface() + err = s.NewDecoderFunc(bytes.NewBuffer(gold)).Decode(got) + require.NoErrorf(t, err, + "failed to %s unmarshal %T from %s", + s.Format, got, s.Golden.FileP(t, s.GoldName), + ) + assert.Equal(t, want, got, + "unmarshaling from golden file does not match expected object", + ) +} diff --git a/testdata/TestAssertJSONMarshaling/custom_marshaling/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/custom_marshaling/marshaled_json.golden new file mode 100644 index 0000000..8b45cb2 --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/custom_marshaling/marshaled_json.golden @@ -0,0 +1,3 @@ +{ + "2fd5af35-b85e-4f03-8eba-524be28d7a5b": "Hello World!=Forty Two" +} diff --git a/testdata/TestAssertJSONMarshaling/empty_struct/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/empty_struct/marshaled_json.golden new file mode 100644 index 0000000..e51d9b9 --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/empty_struct/marshaled_json.golden @@ -0,0 +1,4 @@ +{ + "id": "", + "title": "" +} diff --git a/testdata/TestAssertJSONMarshaling/false_bool_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/false_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/false_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssertJSONMarshaling/full_struct/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/full_struct/marshaled_json.golden new file mode 100644 index 0000000..70de0eb --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/full_struct/marshaled_json.golden @@ -0,0 +1,9 @@ +{ + "id": "cfda163c-d5c1-44a2-909b-5d2ce3a31979", + "title": "The Traveler", + "author": { + "first_name": "John", + "last_name": "Twelve Hawks" + }, + "year": 2005 +} diff --git a/testdata/TestAssertJSONMarshaling/int_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/int_pointer/marshaled_json.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/int_pointer/marshaled_json.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssertJSONMarshaling/partial_struct/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/partial_struct/marshaled_json.golden new file mode 100644 index 0000000..f15d550 --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/partial_struct/marshaled_json.golden @@ -0,0 +1,4 @@ +{ + "id": "cfda163c-d5c1-44a2-909b-5d2ce3a31979", + "title": "The Traveler" +} diff --git a/testdata/TestAssertJSONMarshaling/string_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/string_pointer/marshaled_json.golden new file mode 100644 index 0000000..cd4bc1a --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/string_pointer/marshaled_json.golden @@ -0,0 +1 @@ +"hello world" diff --git a/testdata/TestAssertJSONMarshaling/true_bool_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshaling/true_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssertJSONMarshaling/true_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestAssertJSONMarshalingP/custom_marshaling/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/custom_marshaling/marshaled_json.golden new file mode 100644 index 0000000..8b45cb2 --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/custom_marshaling/marshaled_json.golden @@ -0,0 +1,3 @@ +{ + "2fd5af35-b85e-4f03-8eba-524be28d7a5b": "Hello World!=Forty Two" +} diff --git a/testdata/TestAssertJSONMarshalingP/empty_struct/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/empty_struct/marshaled_json.golden new file mode 100644 index 0000000..92a81ea --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/empty_struct/marshaled_json.golden @@ -0,0 +1,5 @@ +{ + "id": "", + "title": "", + "author": null +} diff --git a/testdata/TestAssertJSONMarshalingP/false_bool_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/false_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/false_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssertJSONMarshalingP/full_struct/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/full_struct/marshaled_json.golden new file mode 100644 index 0000000..1be175d --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/full_struct/marshaled_json.golden @@ -0,0 +1,9 @@ +{ + "id": "10eec54d-e30a-4428-be18-01095d889126", + "title": "Time Travel", + "author": { + "first_name": "Doc", + "last_name": "Brown" + }, + "date": "2021-10-27T22:30:34Z" +} diff --git a/testdata/TestAssertJSONMarshalingP/int_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/int_pointer/marshaled_json.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/int_pointer/marshaled_json.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssertJSONMarshalingP/partial_struct/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/partial_struct/marshaled_json.golden new file mode 100644 index 0000000..42ad618 --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/partial_struct/marshaled_json.golden @@ -0,0 +1,4 @@ +{ + "id": "10eec54d-e30a-4428-be18-01095d889126", + "title": "Time Travel" +} diff --git a/testdata/TestAssertJSONMarshalingP/string_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/string_pointer/marshaled_json.golden new file mode 100644 index 0000000..cd4bc1a --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/string_pointer/marshaled_json.golden @@ -0,0 +1 @@ +"hello world" diff --git a/testdata/TestAssertJSONMarshalingP/true_bool_pointer/marshaled_json.golden b/testdata/TestAssertJSONMarshalingP/true_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssertJSONMarshalingP/true_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestAssertXMLMarshaling/custom_marshaling/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/custom_marshaling/marshaled_xml.golden new file mode 100644 index 0000000..d1cdc64 --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/custom_marshaling/marshaled_xml.golden @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshaling/empty_struct/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/empty_struct/marshaled_xml.golden new file mode 100644 index 0000000..6f87e3c --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/empty_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshaling/false_bool_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/false_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f0f1568 --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/false_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshaling/full_struct/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/full_struct/marshaled_xml.golden new file mode 100644 index 0000000..6defdfd --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/full_struct/marshaled_xml.golden @@ -0,0 +1,9 @@ + + cfda163c-d5c1-44a2-909b-5d2ce3a31979 + The Traveler + + John + Twelve Hawks + + 2005 + \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshaling/int_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/int_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f086c7c --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/int_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshaling/partial_struct/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/partial_struct/marshaled_xml.golden new file mode 100644 index 0000000..a4e50fb --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/partial_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ + + cfda163c-d5c1-44a2-909b-5d2ce3a31979 + The Traveler + \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshaling/string_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/string_pointer/marshaled_xml.golden new file mode 100644 index 0000000..6b0462c --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/string_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshaling/true_bool_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshaling/true_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..603a851 --- /dev/null +++ b/testdata/TestAssertXMLMarshaling/true_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/custom_marshaling/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/custom_marshaling/marshaled_xml.golden new file mode 100644 index 0000000..d1cdc64 --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/custom_marshaling/marshaled_xml.golden @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/empty_struct/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/empty_struct/marshaled_xml.golden new file mode 100644 index 0000000..2f055d7 --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/empty_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ +
+ + +
\ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/false_bool_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/false_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f0f1568 --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/false_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/full_struct/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/full_struct/marshaled_xml.golden new file mode 100644 index 0000000..085f862 --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/full_struct/marshaled_xml.golden @@ -0,0 +1,9 @@ +
+ 10eec54d-e30a-4428-be18-01095d889126 + Time Travel + + Doc + Brown + + 2021-10-27T22:30:34Z +
\ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/int_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/int_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f086c7c --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/int_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/partial_struct/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/partial_struct/marshaled_xml.golden new file mode 100644 index 0000000..3cfa28b --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/partial_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ + + 10eec54d-e30a-4428-be18-01095d889126 + Time Travel + \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/string_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/string_pointer/marshaled_xml.golden new file mode 100644 index 0000000..6b0462c --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/string_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/testdata/TestAssertXMLMarshalingP/true_bool_pointer/marshaled_xml.golden b/testdata/TestAssertXMLMarshalingP/true_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..603a851 --- /dev/null +++ b/testdata/TestAssertXMLMarshalingP/true_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/testdata/TestAssertYAMLMarshaling/custom_marshaling/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/custom_marshaling/marshaled_yaml.golden new file mode 100644 index 0000000..a3926c4 --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/custom_marshaling/marshaled_yaml.golden @@ -0,0 +1,2 @@ +2fd5af35-b85e-4f03-8eba-524be28d7a5b: + Hello World!: Forty Two diff --git a/testdata/TestAssertYAMLMarshaling/empty_struct/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/empty_struct/marshaled_yaml.golden new file mode 100644 index 0000000..aacfe4c --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/empty_struct/marshaled_yaml.golden @@ -0,0 +1,2 @@ +id: "" +title: "" diff --git a/testdata/TestAssertYAMLMarshaling/false_bool_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/false_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/false_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssertYAMLMarshaling/full_struct/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/full_struct/marshaled_yaml.golden new file mode 100644 index 0000000..525af19 --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/full_struct/marshaled_yaml.golden @@ -0,0 +1,6 @@ +id: cfda163c-d5c1-44a2-909b-5d2ce3a31979 +title: The Traveler +author: + first_name: John + last_name: Twelve Hawks +year: 2005 diff --git a/testdata/TestAssertYAMLMarshaling/int_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/int_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/int_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssertYAMLMarshaling/partial_struct/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/partial_struct/marshaled_yaml.golden new file mode 100644 index 0000000..1d272bf --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/partial_struct/marshaled_yaml.golden @@ -0,0 +1,2 @@ +id: cfda163c-d5c1-44a2-909b-5d2ce3a31979 +title: The Traveler diff --git a/testdata/TestAssertYAMLMarshaling/string_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/string_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/string_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +hello world diff --git a/testdata/TestAssertYAMLMarshaling/true_bool_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshaling/true_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssertYAMLMarshaling/true_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestAssertYAMLMarshalingP/custom_marshaling/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/custom_marshaling/marshaled_yaml.golden new file mode 100644 index 0000000..a3926c4 --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/custom_marshaling/marshaled_yaml.golden @@ -0,0 +1,2 @@ +2fd5af35-b85e-4f03-8eba-524be28d7a5b: + Hello World!: Forty Two diff --git a/testdata/TestAssertYAMLMarshalingP/empty_struct/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/empty_struct/marshaled_yaml.golden new file mode 100644 index 0000000..837a18b --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/empty_struct/marshaled_yaml.golden @@ -0,0 +1,3 @@ +id: "" +title: "" +author: null diff --git a/testdata/TestAssertYAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssertYAMLMarshalingP/full_struct/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/full_struct/marshaled_yaml.golden new file mode 100644 index 0000000..53daab0 --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/full_struct/marshaled_yaml.golden @@ -0,0 +1,6 @@ +id: 10eec54d-e30a-4428-be18-01095d889126 +title: Time Travel +author: + first_name: Doc + last_name: Brown +date: 2021-10-27T22:30:34Z diff --git a/testdata/TestAssertYAMLMarshalingP/int_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/int_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/int_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssertYAMLMarshalingP/partial_struct/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/partial_struct/marshaled_yaml.golden new file mode 100644 index 0000000..03aa057 --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/partial_struct/marshaled_yaml.golden @@ -0,0 +1,2 @@ +id: 10eec54d-e30a-4428-be18-01095d889126 +title: Time Travel diff --git a/testdata/TestAssertYAMLMarshalingP/string_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/string_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/string_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +hello world diff --git a/testdata/TestAssertYAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden b/testdata/TestAssertYAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssertYAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestAssert_JSONMarshaling/custom_marshaling/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/custom_marshaling/marshaled_json.golden new file mode 100644 index 0000000..8b45cb2 --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/custom_marshaling/marshaled_json.golden @@ -0,0 +1,3 @@ +{ + "2fd5af35-b85e-4f03-8eba-524be28d7a5b": "Hello World!=Forty Two" +} diff --git a/testdata/TestAssert_JSONMarshaling/empty_struct/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/empty_struct/marshaled_json.golden new file mode 100644 index 0000000..e51d9b9 --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/empty_struct/marshaled_json.golden @@ -0,0 +1,4 @@ +{ + "id": "", + "title": "" +} diff --git a/testdata/TestAssert_JSONMarshaling/false_bool_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/false_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/false_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssert_JSONMarshaling/full_struct/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/full_struct/marshaled_json.golden new file mode 100644 index 0000000..70de0eb --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/full_struct/marshaled_json.golden @@ -0,0 +1,9 @@ +{ + "id": "cfda163c-d5c1-44a2-909b-5d2ce3a31979", + "title": "The Traveler", + "author": { + "first_name": "John", + "last_name": "Twelve Hawks" + }, + "year": 2005 +} diff --git a/testdata/TestAssert_JSONMarshaling/int_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/int_pointer/marshaled_json.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/int_pointer/marshaled_json.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssert_JSONMarshaling/partial_struct/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/partial_struct/marshaled_json.golden new file mode 100644 index 0000000..f15d550 --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/partial_struct/marshaled_json.golden @@ -0,0 +1,4 @@ +{ + "id": "cfda163c-d5c1-44a2-909b-5d2ce3a31979", + "title": "The Traveler" +} diff --git a/testdata/TestAssert_JSONMarshaling/string_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/string_pointer/marshaled_json.golden new file mode 100644 index 0000000..cd4bc1a --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/string_pointer/marshaled_json.golden @@ -0,0 +1 @@ +"hello world" diff --git a/testdata/TestAssert_JSONMarshaling/true_bool_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshaling/true_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssert_JSONMarshaling/true_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestAssert_JSONMarshalingP/custom_marshaling/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/custom_marshaling/marshaled_json.golden new file mode 100644 index 0000000..8b45cb2 --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/custom_marshaling/marshaled_json.golden @@ -0,0 +1,3 @@ +{ + "2fd5af35-b85e-4f03-8eba-524be28d7a5b": "Hello World!=Forty Two" +} diff --git a/testdata/TestAssert_JSONMarshalingP/empty_struct/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/empty_struct/marshaled_json.golden new file mode 100644 index 0000000..92a81ea --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/empty_struct/marshaled_json.golden @@ -0,0 +1,5 @@ +{ + "id": "", + "title": "", + "author": null +} diff --git a/testdata/TestAssert_JSONMarshalingP/false_bool_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/false_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/false_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssert_JSONMarshalingP/full_struct/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/full_struct/marshaled_json.golden new file mode 100644 index 0000000..1be175d --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/full_struct/marshaled_json.golden @@ -0,0 +1,9 @@ +{ + "id": "10eec54d-e30a-4428-be18-01095d889126", + "title": "Time Travel", + "author": { + "first_name": "Doc", + "last_name": "Brown" + }, + "date": "2021-10-27T22:30:34Z" +} diff --git a/testdata/TestAssert_JSONMarshalingP/int_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/int_pointer/marshaled_json.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/int_pointer/marshaled_json.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssert_JSONMarshalingP/partial_struct/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/partial_struct/marshaled_json.golden new file mode 100644 index 0000000..42ad618 --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/partial_struct/marshaled_json.golden @@ -0,0 +1,4 @@ +{ + "id": "10eec54d-e30a-4428-be18-01095d889126", + "title": "Time Travel" +} diff --git a/testdata/TestAssert_JSONMarshalingP/string_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/string_pointer/marshaled_json.golden new file mode 100644 index 0000000..cd4bc1a --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/string_pointer/marshaled_json.golden @@ -0,0 +1 @@ +"hello world" diff --git a/testdata/TestAssert_JSONMarshalingP/true_bool_pointer/marshaled_json.golden b/testdata/TestAssert_JSONMarshalingP/true_bool_pointer/marshaled_json.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssert_JSONMarshalingP/true_bool_pointer/marshaled_json.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestAssert_XMLMarshaling/custom_marshaling/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/custom_marshaling/marshaled_xml.golden new file mode 100644 index 0000000..d1cdc64 --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/custom_marshaling/marshaled_xml.golden @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshaling/empty_struct/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/empty_struct/marshaled_xml.golden new file mode 100644 index 0000000..6f87e3c --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/empty_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshaling/false_bool_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/false_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f0f1568 --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/false_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshaling/full_struct/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/full_struct/marshaled_xml.golden new file mode 100644 index 0000000..6defdfd --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/full_struct/marshaled_xml.golden @@ -0,0 +1,9 @@ + + cfda163c-d5c1-44a2-909b-5d2ce3a31979 + The Traveler + + John + Twelve Hawks + + 2005 + \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshaling/int_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/int_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f086c7c --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/int_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshaling/partial_struct/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/partial_struct/marshaled_xml.golden new file mode 100644 index 0000000..a4e50fb --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/partial_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ + + cfda163c-d5c1-44a2-909b-5d2ce3a31979 + The Traveler + \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshaling/string_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/string_pointer/marshaled_xml.golden new file mode 100644 index 0000000..6b0462c --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/string_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshaling/true_bool_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshaling/true_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..603a851 --- /dev/null +++ b/testdata/TestAssert_XMLMarshaling/true_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/custom_marshaling/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/custom_marshaling/marshaled_xml.golden new file mode 100644 index 0000000..d1cdc64 --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/custom_marshaling/marshaled_xml.golden @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/empty_struct/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/empty_struct/marshaled_xml.golden new file mode 100644 index 0000000..2f055d7 --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/empty_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ +
+ + +
\ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/false_bool_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/false_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f0f1568 --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/false_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/full_struct/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/full_struct/marshaled_xml.golden new file mode 100644 index 0000000..085f862 --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/full_struct/marshaled_xml.golden @@ -0,0 +1,9 @@ +
+ 10eec54d-e30a-4428-be18-01095d889126 + Time Travel + + Doc + Brown + + 2021-10-27T22:30:34Z +
\ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/int_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/int_pointer/marshaled_xml.golden new file mode 100644 index 0000000..f086c7c --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/int_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/partial_struct/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/partial_struct/marshaled_xml.golden new file mode 100644 index 0000000..3cfa28b --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/partial_struct/marshaled_xml.golden @@ -0,0 +1,4 @@ + + 10eec54d-e30a-4428-be18-01095d889126 + Time Travel + \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/string_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/string_pointer/marshaled_xml.golden new file mode 100644 index 0000000..6b0462c --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/string_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/testdata/TestAssert_XMLMarshalingP/true_bool_pointer/marshaled_xml.golden b/testdata/TestAssert_XMLMarshalingP/true_bool_pointer/marshaled_xml.golden new file mode 100644 index 0000000..603a851 --- /dev/null +++ b/testdata/TestAssert_XMLMarshalingP/true_bool_pointer/marshaled_xml.golden @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/testdata/TestAssert_YAMLMarshaling/custom_marshaling/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/custom_marshaling/marshaled_yaml.golden new file mode 100644 index 0000000..a3926c4 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/custom_marshaling/marshaled_yaml.golden @@ -0,0 +1,2 @@ +2fd5af35-b85e-4f03-8eba-524be28d7a5b: + Hello World!: Forty Two diff --git a/testdata/TestAssert_YAMLMarshaling/empty_struct/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/empty_struct/marshaled_yaml.golden new file mode 100644 index 0000000..aacfe4c --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/empty_struct/marshaled_yaml.golden @@ -0,0 +1,2 @@ +id: "" +title: "" diff --git a/testdata/TestAssert_YAMLMarshaling/false_bool_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/false_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/false_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssert_YAMLMarshaling/full_struct/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/full_struct/marshaled_yaml.golden new file mode 100644 index 0000000..525af19 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/full_struct/marshaled_yaml.golden @@ -0,0 +1,6 @@ +id: cfda163c-d5c1-44a2-909b-5d2ce3a31979 +title: The Traveler +author: + first_name: John + last_name: Twelve Hawks +year: 2005 diff --git a/testdata/TestAssert_YAMLMarshaling/int_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/int_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/int_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssert_YAMLMarshaling/partial_struct/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/partial_struct/marshaled_yaml.golden new file mode 100644 index 0000000..1d272bf --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/partial_struct/marshaled_yaml.golden @@ -0,0 +1,2 @@ +id: cfda163c-d5c1-44a2-909b-5d2ce3a31979 +title: The Traveler diff --git a/testdata/TestAssert_YAMLMarshaling/string_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/string_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/string_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +hello world diff --git a/testdata/TestAssert_YAMLMarshaling/true_bool_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshaling/true_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssert_YAMLMarshaling/true_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestAssert_YAMLMarshalingP/custom_marshaling/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/custom_marshaling/marshaled_yaml.golden new file mode 100644 index 0000000..a3926c4 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/custom_marshaling/marshaled_yaml.golden @@ -0,0 +1,2 @@ +2fd5af35-b85e-4f03-8eba-524be28d7a5b: + Hello World!: Forty Two diff --git a/testdata/TestAssert_YAMLMarshalingP/empty_struct/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/empty_struct/marshaled_yaml.golden new file mode 100644 index 0000000..837a18b --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/empty_struct/marshaled_yaml.golden @@ -0,0 +1,3 @@ +id: "" +title: "" +author: null diff --git a/testdata/TestAssert_YAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/false_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +false diff --git a/testdata/TestAssert_YAMLMarshalingP/full_struct/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/full_struct/marshaled_yaml.golden new file mode 100644 index 0000000..53daab0 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/full_struct/marshaled_yaml.golden @@ -0,0 +1,6 @@ +id: 10eec54d-e30a-4428-be18-01095d889126 +title: Time Travel +author: + first_name: Doc + last_name: Brown +date: 2021-10-27T22:30:34Z diff --git a/testdata/TestAssert_YAMLMarshalingP/int_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/int_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/int_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +42 diff --git a/testdata/TestAssert_YAMLMarshalingP/partial_struct/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/partial_struct/marshaled_yaml.golden new file mode 100644 index 0000000..03aa057 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/partial_struct/marshaled_yaml.golden @@ -0,0 +1,2 @@ +id: 10eec54d-e30a-4428-be18-01095d889126 +title: Time Travel diff --git a/testdata/TestAssert_YAMLMarshalingP/string_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/string_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/string_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +hello world diff --git a/testdata/TestAssert_YAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden b/testdata/TestAssert_YAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden new file mode 100644 index 0000000..27ba77d --- /dev/null +++ b/testdata/TestAssert_YAMLMarshalingP/true_bool_pointer/marshaled_yaml.golden @@ -0,0 +1 @@ +true diff --git a/testdata/TestExampleMyBookMarshaling/marshaled_json.golden b/testdata/TestExampleMyBookMarshaling/marshaled_json.golden new file mode 100644 index 0000000..98b9f1d --- /dev/null +++ b/testdata/TestExampleMyBookMarshaling/marshaled_json.golden @@ -0,0 +1,3 @@ +{ + "foo_bar": "Hello World!" +} diff --git a/testdata/TestExampleMyBookMarshaling/marshaled_xml.golden b/testdata/TestExampleMyBookMarshaling/marshaled_xml.golden new file mode 100644 index 0000000..16f856b --- /dev/null +++ b/testdata/TestExampleMyBookMarshaling/marshaled_xml.golden @@ -0,0 +1,3 @@ + + Hello World! + \ No newline at end of file diff --git a/testdata/TestExampleMyBookMarshaling/marshaled_yaml.golden b/testdata/TestExampleMyBookMarshaling/marshaled_yaml.golden new file mode 100644 index 0000000..6783e1f --- /dev/null +++ b/testdata/TestExampleMyBookMarshaling/marshaled_yaml.golden @@ -0,0 +1 @@ +fooBar: Hello World! diff --git a/testdata/TestExampleMyBookMarshalingP/marshaled_json.golden b/testdata/TestExampleMyBookMarshalingP/marshaled_json.golden new file mode 100644 index 0000000..98b9f1d --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingP/marshaled_json.golden @@ -0,0 +1,3 @@ +{ + "foo_bar": "Hello World!" +} diff --git a/testdata/TestExampleMyBookMarshalingP/marshaled_xml.golden b/testdata/TestExampleMyBookMarshalingP/marshaled_xml.golden new file mode 100644 index 0000000..16f856b --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingP/marshaled_xml.golden @@ -0,0 +1,3 @@ + + Hello World! + \ No newline at end of file diff --git a/testdata/TestExampleMyBookMarshalingP/marshaled_yaml.golden b/testdata/TestExampleMyBookMarshalingP/marshaled_yaml.golden new file mode 100644 index 0000000..6783e1f --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingP/marshaled_yaml.golden @@ -0,0 +1 @@ +fooBar: Hello World! diff --git a/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_json.golden b/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_json.golden new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_json.golden @@ -0,0 +1 @@ +{} diff --git a/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_xml.golden b/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_xml.golden new file mode 100644 index 0000000..2859d77 --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_xml.golden @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_yaml.golden b/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_yaml.golden new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingTabular/empty/marshaled_yaml.golden @@ -0,0 +1 @@ +{} diff --git a/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_json.golden b/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_json.golden new file mode 100644 index 0000000..98b9f1d --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_json.golden @@ -0,0 +1,3 @@ +{ + "foo_bar": "Hello World!" +} diff --git a/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_xml.golden b/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_xml.golden new file mode 100644 index 0000000..16f856b --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_xml.golden @@ -0,0 +1,3 @@ + + Hello World! + \ No newline at end of file diff --git a/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_yaml.golden b/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_yaml.golden new file mode 100644 index 0000000..6783e1f --- /dev/null +++ b/testdata/TestExampleMyBookMarshalingTabular/full/marshaled_yaml.golden @@ -0,0 +1 @@ +fooBar: Hello World! diff --git a/update.go b/update.go index e7d7ce9..d655613 100644 --- a/update.go +++ b/update.go @@ -1,6 +1,9 @@ package golden -import "os" +import ( + "os" + "strings" +) var truthyStrings = []string{"1", "y", "t", "yes", "on", "true"} @@ -14,7 +17,7 @@ type UpdateFunc func() bool func EnvUpdateFunc() bool { env := os.Getenv("GOLDEN_UPDATE") for _, v := range truthyStrings { - if env == v { + if strings.ToLower(env) == v { return true } }