📖 4 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"
)
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 Text]

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.

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

YAMLMarshalAsT[EDoc Text]

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.

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 Text]

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.

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