📖 5 min read (~ 900 words).

Yaml

Asserting Yaml Documents

Assertions

GoDoc

All links point to https://pkg.go.dev/github.com/go-openapi/testify/v2

This domain exposes 5 functionalities. Generic assertions are marked with a .

YAMLEq

YAMLEq asserts that two YAML strings are equivalent.

See YAMLEqBytes.

Examples
	panic: "key: value", "key: value"
	should panic without the yaml feature enabled.

YAMLEqBytes

YAMLEqBytes asserts that two YAML slices of bytes are equivalent.

Expected and actual must be valid YAML.

Important

By default, this function is disabled and will panic.

To enable it, you should add a blank import like so:

import(
  "github.com/go-openapi/testify/enable/yaml/v2"
)

For dynamic redaction of the input text via a callback, use YAMLEqT.

Examples
	expected := `---
	key: value
	---
	key: this is a second document, it is not evaluated
	`
	actual := `---
	key: value
	---
	key: this is a subsequent document, it is not evaluated
	`
	assertions.YAMLEq(t, expected, actual)
	panic: []byte("key: value"), []byte("key: value")
	should panic without the yaml feature enabled.

YAMLEqT[EDoc, ADoc RText]

YAMLEqT asserts that two YAML documents are equivalent.

The expected and actual arguments may be string or []byte. They do not need to be of the same type.

See YAMLEqBytes.

NOTE: passed values (expected, actual) may be wrapped as functions to redact the input text dynamically.

Examples
	panic: "key: value", "key: value"
	should panic without the yaml feature enabled.

YAMLMarshalAsT[EDoc RText]

YAMLMarshalAsT wraps YAMLEq after yaml.Marshal.

The input YAML may be a string or []byte.

It fails if the marshaling returns an error or if the expected YAML bytes differ semantically from the expected ones.

NOTE: passed expected value may be wrapped as a function to redact the input text dynamically.

Examples
	actual := struct {
		A int `yaml:"a"`
	}{
		A: 10,
	}
	assertions.YAMLUnmarshalAsT(t,expected, `{"a": 10}`)
	panic: "key: value", "key: value"
	should panic without the yaml feature enabled.

YAMLUnmarshalAsT[Object any, ADoc RText]

YAMLUnmarshalAsT wraps Equal after yaml.Unmarshal.

The input YAML may be a string or []byte.

It fails if the unmarshaling returns an error or if the resulting object is not equal to the expected one.

Be careful not to wrap the expected object into an “any” interface if this is not what you expected: the unmarshaling would take this type to unmarshal as a mapstringany.

NOTE: passed yamlDoc value may be wrapped as a function to redact the input text dynamically.

Examples
	expected := struct {
		A int `yaml:"a"`
	}{
		A: 10,
	}
	assertions.YAMLUnmarshalAsT(t,expected, `{"a": 10}`)
	panic: "key: value", "key: value"
	should panic without the yaml feature enabled.


Generated with github.com/go-openapi/testify/codegen/v2