mv mutiplepath_test, nullvalues_test to api/krusty/, Provide another high level example.

This commit is contained in:
Dingshujie
2019-11-30 15:33:10 +08:00
committed by DingShujie
parent cd84b65972
commit 2d39d64d3a
2 changed files with 13 additions and 26 deletions

View File

@@ -1,16 +1,14 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package target_test
package krusty_test
import (
"strings"
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
func makeCommonFileForMultiplePatchTest(th *kusttest_test.KustTestHarness) {
func makeCommonFileForMultiplePatchTest(th testingHarness) {
th.WriteK("/app/base", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
@@ -89,7 +87,7 @@ configMapGenerator:
}
func TestMultiplePatchesNoConflict(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/overlay/staging")
th := makeTestHarness(t)
makeCommonFileForMultiplePatchTest(th)
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
apiVersion: apps/v1beta2
@@ -130,10 +128,7 @@ spec:
volumes:
- name: nginx-persistent-storage
`)
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
m := th.Run("/app/overlay/staging", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1beta2
kind: Deployment
@@ -233,7 +228,7 @@ metadata:
}
func TestMultiplePatchesWithConflict(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/overlay/staging")
th := makeTestHarness(t)
makeCommonFileForMultiplePatchTest(th)
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
apiVersion: apps/v1beta2
@@ -271,7 +266,7 @@ spec:
- name: ENABLE_FEATURE_FOO
value: FALSE
`)
_, err := th.MakeKustTarget().MakeCustomizedResMap()
err := th.RunWithErr("/app/overlay/staging", th.MakeDefaultOptions())
if err == nil {
t.Fatalf("expected conflict")
}
@@ -325,15 +320,12 @@ spec:
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/overlay/staging")
th := makeTestHarness(t)
makeCommonFileForMultiplePatchTest(th)
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", c.patch1)
th.WriteF("/app/overlay/staging/deployment-patch2.yaml", c.patch2)
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
m := th.Run("/app/overlay/staging", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `apiVersion: apps/v1beta2
kind: Deployment
metadata:
@@ -426,7 +418,7 @@ metadata:
}
func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/overlay/staging")
th := makeTestHarness(t)
makeCommonFileForMultiplePatchTest(th)
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
apiVersion: apps/v1beta2
@@ -452,7 +444,7 @@ spec:
- $patch: delete
name: nginx
`)
_, err := th.MakeKustTarget().MakeCustomizedResMap()
err := th.RunWithErr("/app/overlay/staging", th.MakeDefaultOptions())
if err == nil {
t.Fatalf("Expected error")
}

View File

@@ -1,16 +1,14 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package target_test
package krusty_test
import (
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
func TestNullValues(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app")
th := makeTestHarness(t)
th.WriteF("/app/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
@@ -38,10 +36,7 @@ kind: Kustomization
resources:
- deployment.yaml
`)
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
m := th.Run("/app", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1