MCPcopy Index your code
hub / github.com/databus23/helm-diff / TestNormalizeContent

Function TestNormalizeContent

manifest/normalize_test.go:9–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestNormalizeContent(t *testing.T) {
10 tests := []struct {
11 name string
12 content []byte
13 expectedOutput []byte
14 expectError bool
15 }{
16 {
17 name: "Valid content",
18 content: []byte(`apiVersion: v1
19kind: Pod
20metadata:
21 name: my-pod
22spec:
23 containers:
24 - name: my-container
25 image: nginx`),
26 expectedOutput: []byte(`apiVersion: v1
27kind: Pod
28metadata:
29 name: my-pod
30spec:
31 containers:
32 - image: nginx
33 name: my-container
34`),
35 },
36 {
37 // yaml.v2 marshals a nil map to "{}\n". Empty content never
38 // reaches this path in practice (Parse filters it earlier),
39 // but document the behavior regardless.
40 name: "Empty content",
41 content: []byte(""),
42 expectedOutput: []byte("{}\n"),
43 },
44 {
45 name: "Sequence cannot unmarshal into map",
46 content: []byte("- a\n- b"),
47 expectError: true,
48 },
49 }
50
51 for _, tt := range tests {
52 t.Run(tt.name, func(t *testing.T) {
53 output, err := normalizeContent(tt.content)
54 if tt.expectError {
55 require.Error(t, err)
56 return
57 }
58 require.NoError(t, err)
59 require.Equal(t, tt.expectedOutput, output)
60 })
61 }
62}

Callers

nothing calls this directly

Calls 1

normalizeContentFunction · 0.85

Tested by

no test coverage detected