mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-22 14:57:01 +00:00
add validation and test case
This commit is contained in:
@@ -116,6 +116,9 @@ func (o *addMetadataOptions) validateAndParse(args []string) error {
|
||||
if len(args) < 1 {
|
||||
return fmt.Errorf("must specify %s", o.kind)
|
||||
}
|
||||
if !o.labelsWithoutSelector && o.includeTemplates {
|
||||
return fmt.Errorf("--without-selector flag must be specified for --include-templates to work")
|
||||
}
|
||||
m, err := util.ConvertSliceToMap(args, o.kind.String())
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -294,6 +294,19 @@ func TestAddLabelWithoutSelectorIncludeTemplates(t *testing.T) {
|
||||
assert.Equal(t, m.Labels[0], types.Label{Pairs: map[string]string{"new": "label"}, IncludeTemplates: true})
|
||||
}
|
||||
|
||||
func TestAddLabelIncludeTemplatesWithoutRequiredFlag(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
v := valtest_test.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddLabel(fSys, v.Validator)
|
||||
args := []string{"new:label"}
|
||||
_ = cmd.Flag("include-templates").Value.Set("true")
|
||||
_ = cmd.Flag("without-selector").Value.Set("false")
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyNoCall()
|
||||
require.Error(t, err)
|
||||
require.Containsf(t, err.Error(), "--without-selector flag must be specified for --include-templates to work", "incorrect error: %s", err.Error())
|
||||
}
|
||||
|
||||
func TestAddLabelWithoutSelectorAddLabel(t *testing.T) {
|
||||
var o addMetadataOptions
|
||||
o.metadata = map[string]string{"owls": "cute", "otters": "adorable"}
|
||||
|
||||
Reference in New Issue
Block a user