MCPcopy
hub / github.com/databus23/helm-diff / TestStructuredOutputErrorPaths

Function TestStructuredOutputErrorPaths

diff/diff_test.go:728–810  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

726}
727
728func TestStructuredOutputErrorPaths(t *testing.T) {
729 ansi.DisableColors(true)
730
731 key := "default, failing, ConfigMap (v1)"
732 opts := &Options{OutputFormat: "structured"}
733 validConfigMap := `
734apiVersion: v1
735kind: ConfigMap
736metadata:
737 name: valid
738 namespace: default
739data:
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 })

Callers

nothing calls this directly

Calls 1

ManifestsFunction · 0.85

Tested by

no test coverage detected