mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-18 13:22:17 +00:00
improve tests for alternative kustomization file names
This commit is contained in:
@@ -67,8 +67,9 @@ func NewCmdBuild(
|
||||
pl := plugins.NewLoader(pluginConfig, rf)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "build {path}",
|
||||
Short: "Print configuration per contents of " + pgmconfig.KustomizationFileName0,
|
||||
Use: "build {path}",
|
||||
Short: "Print configuration per contents of " +
|
||||
pgmconfig.DefaultKustomizationFileName(),
|
||||
Example: examples,
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -96,7 +97,8 @@ func NewCmdBuild(
|
||||
func (o *Options) Validate(args []string) (err error) {
|
||||
if len(args) > 1 {
|
||||
return errors.New(
|
||||
"specify one path to " + pgmconfig.KustomizationFileName0)
|
||||
"specify one path to " +
|
||||
pgmconfig.DefaultKustomizationFileName())
|
||||
}
|
||||
if len(args) == 0 {
|
||||
o.kustomizationPath = loader.CWD
|
||||
|
||||
@@ -26,7 +26,9 @@ func TestBuildValidate(t *testing.T) {
|
||||
{"file", []string{"beans"}, "beans", ""},
|
||||
{"path", []string{"a/b/c"}, "a/b/c", ""},
|
||||
{"path", []string{"too", "many"},
|
||||
"", "specify one path to " + pgmconfig.KustomizationFileName0},
|
||||
"",
|
||||
"specify one path to " +
|
||||
pgmconfig.DefaultKustomizationFileName()},
|
||||
}
|
||||
for _, mycase := range cases {
|
||||
opts := Options{}
|
||||
|
||||
@@ -162,7 +162,7 @@ func detectResources(fSys fs.FileSystem, uf ifc.KunstructuredFactory, base strin
|
||||
}
|
||||
// If a sub-directory contains an existing kustomization file add the
|
||||
// directory as a resource and do not decend into it.
|
||||
for _, kfilename := range pgmconfig.KustomizationFileNames() {
|
||||
for _, kfilename := range pgmconfig.RecognizedKustomizationFileNames() {
|
||||
if fSys.Exists(filepath.Join(path, kfilename)) {
|
||||
paths = append(paths, path)
|
||||
return filepath.SkipDir
|
||||
|
||||
@@ -46,8 +46,9 @@ func newCmdAddAnnotation(fSys fs.FileSystem, v func(map[string]string) error) *c
|
||||
o.kind = annotation
|
||||
o.mapValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "annotation",
|
||||
Short: "Adds one or more commonAnnotations to " + pgmconfig.KustomizationFileName0,
|
||||
Use: "annotation",
|
||||
Short: "Adds one or more commonAnnotations to " +
|
||||
pgmconfig.DefaultKustomizationFileName(),
|
||||
Example: `
|
||||
add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -66,8 +67,9 @@ func newCmdAddLabel(fSys fs.FileSystem, v func(map[string]string) error) *cobra.
|
||||
o.kind = label
|
||||
o.mapValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "label",
|
||||
Short: "Adds one or more commonLabels to " + pgmconfig.KustomizationFileName0,
|
||||
Use: "label",
|
||||
Short: "Adds one or more commonLabels to " +
|
||||
pgmconfig.DefaultKustomizationFileName(),
|
||||
Example: `
|
||||
add label {labelKey1:labelValue1},{labelKey2:labelValue2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -47,7 +47,8 @@ func newCmdRemoveAnnotation(fSys fs.FileSystem, v func([]string) error) *cobra.C
|
||||
o.arrayValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "annotation",
|
||||
Short: "Removes one or more commonAnnotations from " + pgmconfig.KustomizationFileName0,
|
||||
Short: "Removes one or more commonAnnotations from " +
|
||||
pgmconfig.DefaultKustomizationFileName(),
|
||||
Example: `
|
||||
remove annotation {annotationKey1},{annotationKey2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -67,7 +68,8 @@ func newCmdRemoveLabel(fSys fs.FileSystem, v func([]string) error) *cobra.Comman
|
||||
o.arrayValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "label",
|
||||
Short: "Removes one or more commonLabels from " + pgmconfig.KustomizationFileName0,
|
||||
Short: "Removes one or more commonLabels from " +
|
||||
pgmconfig.DefaultKustomizationFileName(),
|
||||
Example: `
|
||||
remove label {labelKey1},{labelKey2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -25,7 +25,8 @@ func newCmdRemovePatch(fsys fs.FileSystem) *cobra.Command {
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "patch",
|
||||
Short: "Removes one or more patches from " + pgmconfig.KustomizationFileName0,
|
||||
Short: "Removes one or more patches from " +
|
||||
pgmconfig.DefaultKustomizationFileName(),
|
||||
Example: `
|
||||
remove patch {filepath}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -23,7 +23,8 @@ func newCmdRemoveResource(fsys fs.FileSystem) *cobra.Command {
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "resource",
|
||||
Short: "Removes one or more resource file paths from " + pgmconfig.KustomizationFileName0,
|
||||
Short: "Removes one or more resource file paths from " +
|
||||
pgmconfig.DefaultKustomizationFileName(),
|
||||
Example: `
|
||||
remove resource my-resource.yml
|
||||
remove resource resource1.yml resource2.yml resource3.yml
|
||||
|
||||
@@ -119,7 +119,7 @@ func NewKustomizationFile(fSys fs.FileSystem) (*kustomizationFile, error) { // n
|
||||
func (mf *kustomizationFile) validate() error {
|
||||
match := 0
|
||||
var path []string
|
||||
for _, kfilename := range pgmconfig.KustomizationFileNames() {
|
||||
for _, kfilename := range pgmconfig.RecognizedKustomizationFileNames() {
|
||||
if mf.fSys.Exists(kfilename) {
|
||||
match += 1
|
||||
path = append(path, kfilename)
|
||||
@@ -128,7 +128,9 @@ func (mf *kustomizationFile) validate() error {
|
||||
|
||||
switch match {
|
||||
case 0:
|
||||
return fmt.Errorf("Missing kustomization file '%s'.\n", pgmconfig.KustomizationFileName0)
|
||||
return fmt.Errorf(
|
||||
"Missing kustomization file '%s'.\n",
|
||||
pgmconfig.DefaultKustomizationFileName())
|
||||
case 1:
|
||||
mf.path = path[0]
|
||||
default:
|
||||
@@ -228,7 +230,6 @@ func (mf *kustomizationFile) marshal(kustomization *types.Kustomization) ([]byte
|
||||
return content, nil
|
||||
}
|
||||
output = append(output, content...)
|
||||
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestNewNotExist(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecondarySuffix(t *testing.T) {
|
||||
func TestAllKustomizationFileNames(t *testing.T) {
|
||||
kcontent := `
|
||||
configMapGenerator:
|
||||
- literals:
|
||||
@@ -105,14 +105,16 @@ configMapGenerator:
|
||||
- baz=qux
|
||||
name: my-configmap
|
||||
`
|
||||
fSys := fs.MakeFsInMemory()
|
||||
fSys.WriteFile(pgmconfig.KustomizationFileName1, []byte(kcontent))
|
||||
k, err := NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Error: %v", err)
|
||||
}
|
||||
if k.path != pgmconfig.KustomizationFileName1 {
|
||||
t.Fatalf("Load incorrect file path %s", k.path)
|
||||
for _, n := range pgmconfig.RecognizedKustomizationFileNames() {
|
||||
fSys := fs.MakeFsInMemory()
|
||||
fSys.WriteFile(n, []byte(kcontent))
|
||||
k, err := NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Error: %v", err)
|
||||
}
|
||||
if k.path != n {
|
||||
t.Fatalf("Load incorrect file path %s", k.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ func WriteTestKustomization(fSys fs.FileSystem) {
|
||||
|
||||
// WriteTestKustomizationWith writes content to a well known file name.
|
||||
func WriteTestKustomizationWith(fSys fs.FileSystem, bytes []byte) {
|
||||
fSys.WriteFile(pgmconfig.KustomizationFileName0, bytes)
|
||||
fSys.WriteFile(pgmconfig.DefaultKustomizationFileName(), bytes)
|
||||
}
|
||||
|
||||
// ReadTestKustomization reads content from a well known file name.
|
||||
func ReadTestKustomization(fSys fs.FileSystem) ([]byte, error) {
|
||||
return fSys.ReadFile(pgmconfig.KustomizationFileName0)
|
||||
return fSys.ReadFile(pgmconfig.DefaultKustomizationFileName())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user