(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func 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 |
| 19 | kind: Pod |
| 20 | metadata: |
| 21 | name: my-pod |
| 22 | spec: |
| 23 | containers: |
| 24 | - name: my-container |
| 25 | image: nginx`), |
| 26 | expectedOutput: []byte(`apiVersion: v1 |
| 27 | kind: Pod |
| 28 | metadata: |
| 29 | name: my-pod |
| 30 | spec: |
| 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 | } |
nothing calls this directly
no test coverage detected