fix: Allow patches with empty files with multiple newlines or comments (#5771)

* fix: Add test, when an empty patch file is given, it should not fail

* fix: Add code so there's no error given if an empty file is given as a patch

* chore: Generate plugin with pluginator

* chore: fix tests

Signed-off-by: Julio Chana <julio.chana@lokalise.com>

* Add t.helper() at start of test function

Signed-off-by: Julio Chana <julio.chana@lokalise.com>

---------

Signed-off-by: Julio Chana <julio.chana@lokalise.com>
This commit is contained in:
Julio Chana
2025-03-17 03:15:48 +01:00
committed by GitHub
parent 2643c51364
commit 31b37540e3
3 changed files with 57 additions and 4 deletions

View File

@@ -1108,3 +1108,54 @@ spec:
name: test-deployment
`)
}
func TestPatchTransformerPatchEmpty(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("PatchTransformer")
defer th.Reset()
th.WriteF("patch.yaml", `
`)
th.RunTransformerAndCheckError(`
apiVersion: builtin
kind: PatchTransformer
metadata:
name: notImportantHere
path: patch.yaml
target:
name: myDeploy
`, someDeploymentResources, func(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatalf("unexpected error")
}
})
}
func TestPatchTransformerPatchEmptyOnlyComments(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("PatchTransformer")
defer th.Reset()
th.WriteF("patch.yaml", `
# File with only comments
# Is a virtually empty yaml
`)
th.RunTransformerAndCheckError(`
apiVersion: builtin
kind: PatchTransformer
metadata:
name: notImportantHere
path: patch.yaml
target:
name: myDeploy
`, someDeploymentResources, func(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatalf("unexpected error")
}
})
}