mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Make kubectl label and annotate more consistent
Some of the main changes: - add dryrun to annotate (can push this in a different PR if requested) - use Complete(), Validate() and RunX() - don't place dynamic variables in the options (only user options and args) - call the NewBuilder() in the Run function. You can now do diff between these files and they are as identical as possible.
This commit is contained in:
@@ -323,7 +323,14 @@ func TestLabelErrors(t *testing.T) {
|
||||
for k, v := range testCase.flags {
|
||||
cmd.Flags().Set(k, v)
|
||||
}
|
||||
err := RunLabel(f, buf, cmd, testCase.args, &resource.FilenameOptions{})
|
||||
opts := LabelOptions{}
|
||||
err := opts.Complete(f, buf, cmd, testCase.args)
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
if !testCase.errFn(err) {
|
||||
t.Errorf("%s: unexpected error: %v", k, err)
|
||||
continue
|
||||
@@ -371,10 +378,15 @@ func TestLabelForResourceFromFile(t *testing.T) {
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
cmd := NewCmdLabel(f, buf)
|
||||
options := &resource.FilenameOptions{}
|
||||
options.Filenames = []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}
|
||||
|
||||
err := RunLabel(f, buf, cmd, []string{"a=b"}, options)
|
||||
opts := LabelOptions{FilenameOptions: resource.FilenameOptions{
|
||||
Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}}}
|
||||
err := opts.Complete(f, buf, cmd, []string{"a=b"})
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -398,11 +410,15 @@ func TestLabelLocal(t *testing.T) {
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
cmd := NewCmdLabel(f, buf)
|
||||
cmd.Flags().Set("local", "true")
|
||||
options := &resource.FilenameOptions{
|
||||
Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"},
|
||||
opts := LabelOptions{FilenameOptions: resource.FilenameOptions{
|
||||
Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}}}
|
||||
err := opts.Complete(f, buf, cmd, []string{"a=b"})
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
|
||||
err := RunLabel(f, buf, cmd, []string{"a=b"}, options)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -449,7 +465,15 @@ func TestLabelMultipleObjects(t *testing.T) {
|
||||
cmd := NewCmdLabel(f, buf)
|
||||
cmd.Flags().Set("all", "true")
|
||||
|
||||
if err := RunLabel(f, buf, cmd, []string{"pods", "a=b"}, &resource.FilenameOptions{}); err != nil {
|
||||
opts := LabelOptions{}
|
||||
err := opts.Complete(f, buf, cmd, []string{"pods", "a=b"})
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
if err == nil {
|
||||
err = opts.RunLabel(f, cmd)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if strings.Count(buf.String(), "labeled") != len(pods.Items) {
|
||||
|
||||
Reference in New Issue
Block a user