(t *testing.T)
| 726 | } |
| 727 | |
| 728 | func TestStructuredOutputErrorPaths(t *testing.T) { |
| 729 | ansi.DisableColors(true) |
| 730 | |
| 731 | key := "default, failing, ConfigMap (v1)" |
| 732 | opts := &Options{OutputFormat: "structured"} |
| 733 | validConfigMap := ` |
| 734 | apiVersion: v1 |
| 735 | kind: ConfigMap |
| 736 | metadata: |
| 737 | name: valid |
| 738 | namespace: default |
| 739 | data: |
| 740 | foo: bar |
| 741 | ` |
| 742 | |
| 743 | makeMapping := func(content string) *manifest.MappingResult { |
| 744 | return &manifest.MappingResult{ |
| 745 | Name: key, |
| 746 | Kind: "ConfigMap", |
| 747 | Content: content, |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | t.Run("InvalidNewManifestYAML", func(t *testing.T) { |
| 752 | oldIndex := map[string]*manifest.MappingResult{ |
| 753 | key: makeMapping(validConfigMap), |
| 754 | } |
| 755 | newIndex := map[string]*manifest.MappingResult{ |
| 756 | key: makeMapping(":\n not-valid: value"), |
| 757 | } |
| 758 | |
| 759 | var buf bytes.Buffer |
| 760 | changed := Manifests(oldIndex, newIndex, opts, &buf) |
| 761 | require.True(t, changed, "Should report resource-level change even when YAML parsing fails") |
| 762 | |
| 763 | var entries []StructuredEntry |
| 764 | require.NoError(t, json.Unmarshal(buf.Bytes(), &entries)) |
| 765 | require.Len(t, entries, 1) |
| 766 | require.Equal(t, "MODIFY", entries[0].ChangeType) |
| 767 | }) |
| 768 | |
| 769 | t.Run("InvalidOldManifestYAML", func(t *testing.T) { |
| 770 | oldIndex := map[string]*manifest.MappingResult{ |
| 771 | key: makeMapping("metadata:\n name: invalid\n namespace: default\n labels:\n : bad"), |
| 772 | } |
| 773 | newIndex := map[string]*manifest.MappingResult{ |
| 774 | key: makeMapping(validConfigMap), |
| 775 | } |
| 776 | |
| 777 | var buf bytes.Buffer |
| 778 | changed := Manifests(oldIndex, newIndex, opts, &buf) |
| 779 | require.True(t, changed, "Should report resource-level change even when YAML parsing fails") |
| 780 | |
| 781 | var entries []StructuredEntry |
| 782 | require.NoError(t, json.Unmarshal(buf.Bytes(), &entries)) |
| 783 | require.Len(t, entries, 1) |
| 784 | require.Equal(t, "MODIFY", entries[0].ChangeType) |
| 785 | }) |
nothing calls this directly
no test coverage detected