Documentation
¶
Overview ¶
Package fixtures exposes a test Harness utility to test JSON and YAML transformations.
Index ¶
- Variables
- func AssertYAMLEq(t testing.TB, expected string, actual string, msgAndArgs ...any) bool
- func JSONEqualOrdered(t testing.TB, expected, actual string)
- func MustLoadFixture(fsys fs.FS, pth string) []byte
- func RequireYAMLEq(t testing.TB, expected string, actual string, msgAndArgs ...any)
- func ShouldLoadFixture(t testing.TB, fsys fs.FS, pth string) []byte
- func YAMLEqualOrdered(t testing.TB, expected, actual string)
- type Filter
- type Fixture
- type Harness
- type TestCases
Constants ¶
This section is empty.
Variables ¶
var EmbeddedFixtures embed.FS
Functions ¶
func AssertYAMLEq ¶
AssertYAMLEq is the same as assert.YAMLEq but without the dependency to go.pkg.in/yaml.v3.
NOTE: this could be reverted once https://github.com/stretchr/testify/pull/1772 is merged.
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 RequireYAMLEq ¶
RequireYAMLEq is the same as require.YAMLEq but without the dependency to go.pkg.in/yaml.v3.
NOTE: this could be reverted once https://github.com/stretchr/testify/pull/1772 is merged.
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.
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.