improve tests for alternative kustomization file names

This commit is contained in:
Jeffrey Regan
2019-10-04 10:17:49 -07:00
parent 404d2d631a
commit 07e0e46ac7
15 changed files with 61 additions and 43 deletions

View File

@@ -74,7 +74,10 @@ func (th *KustTestHarness) WriteF(dir string, content string) {
}
func (th *KustTestHarness) WriteK(dir string, content string) {
th.WriteF(filepath.Join(dir, pgmconfig.KustomizationFileName0), `
th.WriteF(
filepath.Join(
dir,
pgmconfig.DefaultKustomizationFileName()), `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
`+content)

View File

@@ -389,7 +389,8 @@ func TestNewLoaderAtGitClone(t *testing.T) {
fSys.MkdirAll(coRoot)
fSys.MkdirAll(coRoot + "/" + pathInRepo)
fSys.WriteFile(
coRoot+"/"+pathInRepo+"/"+pgmconfig.KustomizationFileName0,
coRoot+"/"+pathInRepo+"/"+
pgmconfig.DefaultKustomizationFileName(),
[]byte(`
whatever
`))

View File

@@ -4,22 +4,23 @@
// Package pgmconfig holds global constants for the kustomize tool.
package pgmconfig
// KustomizationFileNames is a list of filenames
// RecognizedKustomizationFileNames is a list of file names
// that kustomize recognizes.
// To avoid ambiguity, a directory cannot contain
// more than one match to this list.
func KustomizationFileNames() []string {
// To avoid ambiguity, a kustomization directory may not
// contain more than one match to this list.
func RecognizedKustomizationFileNames() []string {
return []string{
KustomizationFileName0,
KustomizationFileName1,
KustomizationFileName2}
"kustomization.yaml",
"kustomization.yml",
"Kustomization",
}
}
func DefaultKustomizationFileName() string {
return RecognizedKustomizationFileNames()[0]
}
const (
KustomizationFileName0 = "kustomization.yaml"
KustomizationFileName1 = "kustomization.yml"
KustomizationFileName2 = "Kustomization"
// An environment variable to consult for kustomization
// configuration data. See:
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

View File

@@ -11,7 +11,7 @@ import (
"testing"
kusttest_test "sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pkg/plugins/testenv"
"sigs.k8s.io/kustomize/v3/pkg/plugins/testenv"
)
// This is an example of using a helm chart as a base,

View File

@@ -81,7 +81,7 @@ func commaOr(q []string) string {
func loadKustFile(ldr ifc.Loader) ([]byte, error) {
var content []byte
match := 0
for _, kf := range pgmconfig.KustomizationFileNames() {
for _, kf := range pgmconfig.RecognizedKustomizationFileNames() {
c, err := ldr.Load(kf)
if err == nil {
match += 1
@@ -92,7 +92,7 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
case 0:
return nil, fmt.Errorf(
"unable to find one of %v in directory '%s'",
commaOr(quoted(pgmconfig.KustomizationFileNames())),
commaOr(quoted(pgmconfig.RecognizedKustomizationFileNames())),
ldr.Root())
case 1:
return content, nil