MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / UnmarshalInto

Function UnmarshalInto

internal/testing/require/encoding.go:19–40  ·  view source on GitHub ↗

UnmarshalInto parses input as YAML (or JSON) the same way as the Kubernetes API Server writing into output. It calls t.Fatal when something fails.

(
	t testing.TB, output Destination, input Data,
)

Source from the content-addressed store, hash-verified

17// UnmarshalInto parses input as YAML (or JSON) the same way as the Kubernetes
18// API Server writing into output. It calls t.Fatal when something fails.
19func UnmarshalInto[Data ~string | ~[]byte, Destination *T, T any](
20 t testing.TB, output Destination, input Data,
21) {
22 t.Helper()
23
24 // The REST API uses serializers:
25 //
26 // https://pkg.go.dev/k8s.io/apimachinery/pkg/runtime/serializer/json
27 // https://pkg.go.dev/k8s.io/apimachinery/pkg/runtime/serializer/yaml
28 //
29 // The util package follows similar paths (strict, preserve ints, etc.)
30 //
31 // https://pkg.go.dev/k8s.io/apimachinery/pkg/util/json
32 // https://pkg.go.dev/k8s.io/apimachinery/pkg/util/yaml
33
34 data, err := yaml.YAMLToJSONStrict([]byte(input))
35 assert.NilError(t, err)
36
37 strict, err := json.UnmarshalStrict(data, output)
38 assert.NilError(t, err)
39 assert.NilError(t, errors.Join(strict...))
40}
41
42// UnmarshalIntoField parses input as YAML (or JSON) the same way as the Kubernetes API Server.
43// The result goes into a (nested) field of output. It calls t.Fatal when something fails.

Callers 15

TestExporterEnabledFunction · 0.92
TestLargestWholeCPUFunction · 0.92
TestGeneratePostgresHBAFunction · 0.92
TestGeneratePostgresHBAsFunction · 0.92
TestPatroniLogSizeFunction · 0.92
TestGenerateConfigFunction · 0.92

Calls 1

HelperMethod · 0.80

Tested by 15

TestExporterEnabledFunction · 0.74
TestLargestWholeCPUFunction · 0.74
TestGeneratePostgresHBAFunction · 0.74
TestGeneratePostgresHBAsFunction · 0.74
TestPatroniLogSizeFunction · 0.74
TestGenerateConfigFunction · 0.74