mv generatormergeandreplace_test, generatoroptions_test to api/krusty/, Provide another high level example.

This commit is contained in:
Dingshujie
2019-11-30 15:41:11 +08:00
committed by DingShujie
parent 2d39d64d3a
commit cbfe314778
2 changed files with 19 additions and 41 deletions

View File

@@ -1,17 +1,15 @@
// 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 TestSimpleBase(t *testing.T) { func TestSimpleBase(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/base") th := makeTestHarness(t)
th.WriteK("/app/base", ` th.WriteK("/app/base", `
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
@@ -72,10 +70,7 @@ spec:
- name: nginx - name: nginx
image: nginx image: nginx
`) `)
m, err := th.MakeKustTarget().MakeCustomizedResMap() m := th.Run("/app/base", th.MakeDefaultOptions())
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, ` th.AssertActualEqualsExpected(m, `
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
@@ -151,7 +146,7 @@ spec:
`) `)
} }
func makeBaseWithGenerators(th *kusttest_test.KustTestHarness) { func makeBaseWithGenerators(th testingHarness) {
th.WriteK("/app", ` th.WriteK("/app", `
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
@@ -217,12 +212,9 @@ spec:
} }
func TestBaseWithGeneratorsAlone(t *testing.T) { func TestBaseWithGeneratorsAlone(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app") th := makeTestHarness(t)
makeBaseWithGenerators(th) makeBaseWithGenerators(th)
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/v1beta2 apiVersion: apps/v1beta2
kind: Deployment kind: Deployment
@@ -311,7 +303,7 @@ type: Opaque
} }
func TestMergeAndReplaceGenerators(t *testing.T) { func TestMergeAndReplaceGenerators(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/overlay") th := makeTestHarness(t)
makeBaseWithGenerators(th) makeBaseWithGenerators(th)
th.WriteF("/overlay/deployment.yaml", ` th.WriteF("/overlay/deployment.yaml", `
apiVersion: apps/v1beta2 apiVersion: apps/v1beta2
@@ -355,10 +347,7 @@ secretGenerator:
literals: literals:
- proxy=haproxy - proxy=haproxy
`) `)
m, err := th.MakeKustTarget().MakeCustomizedResMap() m := th.Run("/overlay", 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
@@ -469,7 +458,7 @@ metadata:
} }
func TestGeneratingIntoNamespaces(t *testing.T) { func TestGeneratingIntoNamespaces(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app") th := makeTestHarness(t)
th.WriteK("/app", ` th.WriteK("/app", `
configMapGenerator: configMapGenerator:
- name: test - name: test
@@ -492,10 +481,7 @@ secretGenerator:
- username=admin - username=admin
- password=somepw - password=somepw
`) `)
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: v1 apiVersion: v1
data: data:
@@ -538,7 +524,7 @@ type: Opaque
// Valid that conflict is detected is the name are identical // Valid that conflict is detected is the name are identical
// and namespace left to default // and namespace left to default
func TestConfigMapGeneratingIntoSameNamespace(t *testing.T) { func TestConfigMapGeneratingIntoSameNamespace(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app") th := makeTestHarness(t)
th.WriteK("/app", ` th.WriteK("/app", `
configMapGenerator: configMapGenerator:
- name: test - name: test
@@ -549,7 +535,7 @@ configMapGenerator:
literals: literals:
- key=value - key=value
`) `)
_, err := th.MakeKustTarget().MakeCustomizedResMap() err := th.RunWithErr("/app", th.MakeDefaultOptions())
if err == nil { if err == nil {
t.Fatalf("expected error") t.Fatalf("expected error")
} }
@@ -561,7 +547,7 @@ configMapGenerator:
// Valid that conflict is detected is the name are identical // Valid that conflict is detected is the name are identical
// and namespace left to default // and namespace left to default
func TestSecretGeneratingIntoSameNamespace(t *testing.T) { func TestSecretGeneratingIntoSameNamespace(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app") th := makeTestHarness(t)
th.WriteK("/app", ` th.WriteK("/app", `
secretGenerator: secretGenerator:
- name: test - name: test
@@ -574,7 +560,7 @@ secretGenerator:
- username=admin - username=admin
- password=somepw - password=somepw
`) `)
_, err := th.MakeKustTarget().MakeCustomizedResMap() err := th.RunWithErr("/app", 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 TestSecretGenerator(t *testing.T) { func TestSecretGenerator(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app") th := makeTestHarness(t)
th.WriteK("/app", ` th.WriteK("/app", `
secretGenerator: secretGenerator:
- name: bob - name: bob
@@ -28,10 +26,7 @@ MOUNTAIN=everest
OCEAN=pacific OCEAN=pacific
`) `)
th.WriteF("/app/phrase.dat", "dat phrase") th.WriteF("/app/phrase.dat", "dat phrase")
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: v1 apiVersion: v1
data: data:
@@ -49,7 +44,7 @@ type: Opaque
} }
func TestGeneratorOptionsWithBases(t *testing.T) { func TestGeneratorOptionsWithBases(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/overlay") th := makeTestHarness(t)
th.WriteK("/app/base", ` th.WriteK("/app/base", `
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
@@ -76,10 +71,7 @@ configMapGenerator:
literals: literals:
- fruit=apple - fruit=apple
`) `)
m, err := th.MakeKustTarget().MakeCustomizedResMap() m := th.Run("/app/overlay", th.MakeDefaultOptions())
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, ` th.AssertActualEqualsExpected(m, `
apiVersion: v1 apiVersion: v1
data: data: