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

View File

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