Documentation
¶
Overview ¶
Package fixtures exposes a test Harness utility to test JSON and YAML transformations.
Index ¶
- Variables
- func JSONEqualOrdered(t testing.TB, expected, actual string)
- func JSONEqualOrderedBytes(t testing.TB, expected, actual []byte)
- func MustLoadFixture(fsys fs.FS, pth string) []byte
- func ShouldLoadFixture(t testing.TB, fsys fs.FS, pth string) []byte
- func YAMLEqualOrdered(t testing.TB, expected, actual string)
- func YAMLEqualOrderedBytes(t testing.TB, expected, actual []byte)
- type Filter
- type Fixture
- type Harness
- type TestCases
Constants ¶
This section is empty.
Variables ¶
var EmbeddedFixtures embed.FS
Functions ¶
func JSONEqualOrdered ¶
JSONEqualOrdered is a replacement for require.JSONEq that checks further that two JSONs are exactly equal, with only the following tolerated differences:
- non-significant white space
- numerical encoding (e.g. 0.01 <=> 1e-2)
- unicode encoding (e.g. explicitly escaped unicode sequences <=> unicode rune)
func JSONEqualOrderedBytes ¶ added in v0.25.2
JSONEqualOrderedBytes is a replacement for require.JSONEqBytes that checks further that two JSONs are exactly equal. See JSONEqualOrdered.
func YAMLEqualOrdered ¶
YAMLEqualOrdered is a replacement for require.YAMLEq that checks further that two YAML are exactly equal, with only the following tolerated differences:
- non-significant white space
- comments
Otherwise, the representation of arrays, null values and objects must match exactly, e.g this checks tells us that:
a: [1,2,3]
differs from:
a: - 1 - 2 - 3
even though we know that they have equivalent semantics.
NOTE: at this moment, this check does not support anchors.
func YAMLEqualOrderedBytes ¶ added in v0.25.2
Types ¶
type Filter ¶
type Filter func(*filters)
func WithExcludePattern ¶
func WithIncludePattern ¶
func WithoutError ¶
type Fixture ¶
type Fixture struct {
Name string `yaml:"name"`
Comment string `yaml:"comment"`
JSONPayload string `yaml:"json_payload"`
YAMLPayload string `yaml:"yaml_payload"`
Error bool `yaml:"error"`
ErrorContains string `yaml:"error_contains"`
}
Fixture holds a JSON payload and its equivalent YAML payload.
func (Fixture) ExpectError ¶
ExpectError indicates if this test case expect an error.
type Harness ¶
type Harness struct {
// contains filtered or unexported fields
}
Harness is a test helper to retrieve or scan over a collection of predefined test cases loaded from the embedded file system.
func NewHarness ¶
NewHarness yields a new test Harness for a given test.
The Harness requires a call to Harness.Init to be ready.