Add test covering pod disruption budget treatment.

This commit is contained in:
monopole
2021-01-15 06:09:52 -08:00
parent 64ffbcb15d
commit fabaf35c72

View File

@@ -10,8 +10,52 @@ import (
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
) )
// Demonstrate unwanted quotes added to an integer by a strategic merge patch. func TestPodDisruptionBudgetBasics(t *testing.T) {
func TestIssue3424Basics(t *testing.T) { th := kusttest_test.MakeHarness(t)
th.WriteF("pdbLiteral.yaml", `
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: pdbLiteral
spec:
maxUnavailable: 90
`)
th.WriteF("pdbPercentage.yaml", `
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: pdbPercentage
spec:
maxUnavailable: 90%
`)
th.WriteK(".", `
resources:
- pdbLiteral.yaml
- pdbPercentage.yaml
`)
m := th.Run(".", th.MakeDefaultOptions())
// In a PodDisruptionBudget, the fields maxUnavailable
// minAvailable are mutually exclusive, and both can hold
// either an integer, i.e. 10, or string that has to be
// an int followed by a percent sign, e.g. 10%.
th.AssertActualEqualsExpected(m, `
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: pdbLiteral
spec:
maxUnavailable: 90
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: pdbPercentage
spec:
maxUnavailable: 90%
`)
}
func TestPodDisruptionBudgetMerging(t *testing.T) {
th := kusttest_test.MakeHarness(t) th := kusttest_test.MakeHarness(t)
opts := th.MakeDefaultOptions() opts := th.MakeDefaultOptions()
th.WriteF("pdb-patch.yaml", ` th.WriteF("pdb-patch.yaml", `
@@ -73,6 +117,10 @@ metadata:
spec: spec:
maxUnavailable: %s maxUnavailable: %s
` `
// In a PodDisruptionBudget, the fields maxUnavailable
// minAvailable are mutually exclusive, and both can hold
// either an integer, i.e. 10, or string that has to be
// an int followed by a percent sign, e.g. 10%.
th.AssertActualEqualsExpected(m, opts.IfApiMachineryElseKyaml( th.AssertActualEqualsExpected(m, opts.IfApiMachineryElseKyaml(
fmt.Sprintf(expFmt, `"1"`, `"1"`), fmt.Sprintf(expFmt, `"1"`, `"1"`),
fmt.Sprintf(expFmt, `1`, `1`))) fmt.Sprintf(expFmt, `1`, `1`)))