Make kusttestharness shareable.

This commit is contained in:
Jeffrey Regan
2019-05-07 14:18:35 -07:00
parent 8c5d4128e0
commit bcc7412ef2
23 changed files with 389 additions and 343 deletions

View File

@@ -19,10 +19,11 @@ import (
"sigs.k8s.io/kustomize/internal/plugintest"
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
"sigs.k8s.io/kustomize/pkg/kusttest"
)
func writeServiceGenerator(th *KustTestHarness, path string) {
th.writeF(path, `
func writeServiceGenerator(th *kusttest_test.KustTestHarness, path string) {
th.WriteF(path, `
apiVersion: someteam.example.com/v1
kind: ServiceGenerator
metadata:
@@ -39,18 +40,18 @@ func TestServiceGeneratorPlugin(t *testing.T) {
tc.BuildGoPlugin(
"someteam.example.com", "v1", "ServiceGenerator")
th := NewKustTestHarnessWithPluginConfig(
th := kusttest_test.NewKustTestHarnessWithPluginConfig(
t, "/app", plugin.ActivePluginConfig())
th.writeK("/app", `
th.WriteK("/app", `
generators:
- serviceGenerator.yaml
`)
writeServiceGenerator(th, "/app/serviceGenerator.yaml")
m, err := th.makeKustTarget().MakeCustomizedResMap()
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.assertActualEqualsExpected(m, `
th.AssertActualEqualsExpected(m, `
apiVersion: v1
kind: Service
metadata:
@@ -65,13 +66,12 @@ spec:
`)
}
func writeSecretGeneratorConfig(th *KustTestHarness, root string) {
th.writeF(filepath.Join(root, "secretGenerator.yaml"), `
func writeSecretGeneratorConfig(th *kusttest_test.KustTestHarness, root string) {
th.WriteF(filepath.Join(root, "secretGenerator.yaml"), `
apiVersion: builtin
kind: SecretGenerator
metadata:
name: secretGenerator
name: mySecret
behavior: merge
envFiles:
- a.env
@@ -82,13 +82,13 @@ literals:
- FRUIT=apple
- VEGETABLE=carrot
`)
th.writeF(filepath.Join(root, "a.env"), `
th.WriteF(filepath.Join(root, "a.env"), `
ROUTER_PASSWORD=admin
`)
th.writeF(filepath.Join(root, "b.env"), `
th.WriteF(filepath.Join(root, "b.env"), `
DB_PASSWORD=iloveyou
`)
th.writeF(filepath.Join(root, "longsecret.txt"), `
th.WriteF(filepath.Join(root, "longsecret.txt"), `
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
@@ -104,18 +104,18 @@ func TestSecretGenerator(t *testing.T) {
tc.BuildGoPlugin(
"builtin", "", "SecretGenerator")
th := NewKustTestHarnessWithPluginConfig(
th := kusttest_test.NewKustTestHarnessWithPluginConfig(
t, "/app", plugin.ActivePluginConfig())
th.writeK("/app", `
th.WriteK("/app", `
generators:
- secretGenerator.yaml
`)
writeSecretGeneratorConfig(th, "/app")
m, err := th.makeKustTarget().MakeCustomizedResMap()
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.assertActualEqualsExpected(m, `
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
DB_PASSWORD: aWxvdmV5b3U=
@@ -137,24 +137,24 @@ func TestConfigMapGenerator(t *testing.T) {
tc.BuildExecPlugin(
"someteam.example.com", "v1", "ConfigMapGenerator")
th := NewKustTestHarnessWithPluginConfig(
th := kusttest_test.NewKustTestHarnessWithPluginConfig(
t, "/app", plugin.ActivePluginConfig())
th.writeK("/app", `
th.WriteK("/app", `
generators:
- configmapGenerator.yaml
`)
th.writeF("/app/configmapGenerator.yaml", `
th.WriteF("/app/configmapGenerator.yaml", `
apiVersion: someteam.example.com/v1
kind: ConfigMapGenerator
metadata:
name: some-random-name
argsOneLiner: "admin secret"
`)
m, err := th.makeKustTarget().MakeCustomizedResMap()
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.assertActualEqualsExpected(m, `
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
password: secret