|
|
@ -22,6 +22,7 @@ package main
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"text/template"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -118,6 +119,8 @@ spec:
|
|
|
|
cluster_region: "eu-central-1"
|
|
|
|
cluster_region: "eu-central-1"
|
|
|
|
`
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tmpFile := filepath.Join(t.TempDir(), "podinfo.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
name string
|
|
|
|
args string
|
|
|
|
args string
|
|
|
@ -132,25 +135,25 @@ spec:
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "build podinfo",
|
|
|
|
name: "build podinfo",
|
|
|
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/podinfo",
|
|
|
|
args: "build kustomization podinfo --kustomization-file " + tmpFile + " --path ./testdata/build-kustomization/podinfo",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "build podinfo without service",
|
|
|
|
name: "build podinfo without service",
|
|
|
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/delete-service",
|
|
|
|
args: "build kustomization podinfo --kustomization-file " + tmpFile + " --path ./testdata/build-kustomization/delete-service",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-without-service-result.yaml",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "build deployment and configmap with var substitution",
|
|
|
|
name: "build deployment and configmap with var substitution",
|
|
|
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/var-substitution",
|
|
|
|
args: "build kustomization podinfo --kustomization-file " + tmpFile + " --path ./testdata/build-kustomization/var-substitution",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "build deployment and configmap with var substitution in dry-run mode",
|
|
|
|
name: "build deployment and configmap with var substitution in dry-run mode",
|
|
|
|
args: "build kustomization podinfo --kustomization-file ./testdata/build-kustomization/podinfo.yaml --path ./testdata/build-kustomization/var-substitution --dry-run",
|
|
|
|
args: "build kustomization podinfo --kustomization-file " + tmpFile + " --path ./testdata/build-kustomization/var-substitution --dry-run",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
|
|
|
resultFile: "./testdata/build-kustomization/podinfo-with-var-substitution-result.yaml",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
assertFunc: "assertGoldenTemplateFile",
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -161,8 +164,6 @@ spec:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setup(t, tmpl)
|
|
|
|
setup(t, tmpl)
|
|
|
|
|
|
|
|
|
|
|
|
testEnv.CreateObjectFile("./testdata/build-kustomization/podinfo-source.yaml", tmpl, t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp, err := template.New("podinfo").Parse(podinfo)
|
|
|
|
temp, err := template.New("podinfo").Parse(podinfo)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
t.Fatal(err)
|
|
|
@ -174,11 +175,10 @@ spec:
|
|
|
|
t.Fatal(err)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = os.WriteFile("./testdata/build-kustomization/podinfo.yaml", b.Bytes(), 0666)
|
|
|
|
err = os.WriteFile(tmpFile, b.Bytes(), 0666)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Cleanup(func() { _ = os.Remove("./testdata/build-kustomization/podinfo.yaml") })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|