Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugin/builtin/patchtransformer/PatchTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ func (p *plugin) Config(h *resmap.PluginHelpers, c []byte) error {
patchesSM, errSM := h.ResmapFactory().RF().SliceFromBytes([]byte(p.patchText))
patchesJson, errJson := jsonPatchFromBytes([]byte(p.patchText))

if (errSM == nil && errJson == nil) ||
(patchesSM != nil && patchesJson != nil) {
if ((errSM == nil && errJson == nil) ||
(patchesSM != nil && patchesJson != nil)) &&
(len(patchesSM) > 0 && len(patchesJson) > 0) {
return fmt.Errorf(
"illegally qualifies as both an SM and JSON patch: %s",
p.patchSource)
Expand Down
29 changes: 29 additions & 0 deletions plugin/builtin/patchtransformer/PatchTransformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,32 @@ spec:
name: test-deployment
`)
}

func TestPatchTransformerPatchEmpty(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("PatchTransformer")
defer th.Reset()

th.RunTransformerAndCheckError(`
`, someDeploymentResources, func(t *testing.T, err error) {
if err != nil {
t.Fatalf("unexpected error")
}
})
}

func TestPatchTransformerPatchEmptyOnlyComments(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("PatchTransformer")
defer th.Reset()

th.RunTransformerAndCheckError(`
# File with only comments

# Is a virtually empty yaml
`, someDeploymentResources, func(t *testing.T, err error) {
if err != nil {
t.Fatalf("unexpected error")
}
})
}