From 6598c02e1822373defa7f1f98cd41d7c3f972e56 Mon Sep 17 00:00:00 2001 From: yutaroyamanaka Date: Sat, 8 Apr 2023 22:18:02 +0900 Subject: [PATCH] add test cases for generators and kustomize.config.k8s.io annotations --- api/krusty/generatorplugin_test.go | 132 +++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 api/krusty/generatorplugin_test.go diff --git a/api/krusty/generatorplugin_test.go b/api/krusty/generatorplugin_test.go new file mode 100644 index 00000000000..68d5b3ec612 --- /dev/null +++ b/api/krusty/generatorplugin_test.go @@ -0,0 +1,132 @@ +package krusty_test + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" + "sigs.k8s.io/kustomize/kyaml/filesys" +) + +func TestGeneratorHashSuffixWithMergeBehavior(t *testing.T) { + fSys := filesys.MakeFsOnDisk() + generatorFilename := "generateWithHashRequest.sh" + + th := kusttest_test.MakeHarnessWithFs(t, fSys) + o := th.MakeOptionsPluginsEnabled() + o.PluginConfig.FnpLoadingOptions.EnableExec = true + + tmpDir, err := filesys.NewTmpConfirmedDir() + assert.NoError(t, err) + th.WriteK(tmpDir.String(), ` +resources: +- configmap.yaml +generators: +- |- + kind: Executable + metadata: + name: demo + annotations: + config.kubernetes.io/function: | + exec: + path: ./`+generatorFilename+` +`) + + th.WriteF(filepath.Join(tmpDir.String(), "configmap.yaml"), ` +apiVersion: v1 +kind: ConfigMap +metadata: + name: cmap +data: + a: b +`) + th.WriteF(filepath.Join(tmpDir.String(), generatorFilename), `#!/bin/sh + +cat <