Support multiple arguments on revision delete (#657)

* added multiple parameters to revision and added e2e test

* add to changelog

* fix changelog table

* fix warning message and revision test

* remove commented lines

* remove 'successfully' from revision output

* added requires one or more revision name

* remove absent revision pre check

* re add nonexist revision

* fixed tests
This commit is contained in:
wslyln 2020-02-13 22:45:40 -08:00 committed by GitHub
parent 52b56baf52
commit 12d718e7af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 13 deletions

View File

@ -20,6 +20,10 @@
|===
| | Description | PR
| 🧽
| Support multiple revisions on `kn revision delete`
| https://github.com/knative/client/pull/657[#657]
| 🎁
| Add human readable `kn route describe`
| https://github.com/knative/client/pull/643[#643]
@ -48,6 +52,7 @@
| 🐛
| Fix `--image` flag to only allow single occurence
| https://github.com/knative/client/pull/647[#647]
|===
## v0.12.0 (2020-01-29)

View File

@ -32,8 +32,8 @@ func NewRevisionDeleteCommand(p *commands.KnParams) *cobra.Command {
# Delete a revision 'svc1-abcde' in default namespace
kn revision delete svc1-abcde`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("'revision delete' requires the revision name given as single argument")
if len(args) < 1 {
return errors.New("'kn revision delete' requires one or more revision name")
}
namespace, err := p.GetNamespace(cmd)
if err != nil {
@ -43,11 +43,15 @@ func NewRevisionDeleteCommand(p *commands.KnParams) *cobra.Command {
if err != nil {
return err
}
err = client.DeleteRevision(args[0])
if err != nil {
return err
for _, name := range args {
err = client.DeleteRevision(name)
if err != nil {
fmt.Fprintf(cmd.OutOrStdout(), "%s.\n", err)
} else {
fmt.Fprintf(cmd.OutOrStdout(), "Revision '%s' deleted in namespace '%s'.\n", name, namespace)
}
}
fmt.Fprintf(cmd.OutOrStdout(), "Revision '%s' successfully deleted in namespace '%s'.\n", args[0], namespace)
return nil
},
}

View File

@ -60,3 +60,22 @@ func TestRevisionDelete(t *testing.T) {
}
assert.Check(t, util.ContainsAll(output, "Revision", revName, "deleted", "namespace", commands.FakeNamespace))
}
func TestMultipleRevisionDelete(t *testing.T) {
revName1 := "foo-12345"
revName2 := "foo-67890"
revName3 := "foo-abcde"
action, _, output, err := fakeRevisionDelete([]string{"revision", "delete", revName1, revName2, revName3})
if err != nil {
t.Error(err)
return
}
if action == nil {
t.Errorf("No action")
} else if !action.Matches("delete", "revisions") {
t.Errorf("Bad action %v", action)
}
assert.Check(t, util.ContainsAll(output, "Revision", revName1, "deleted", "namespace", commands.FakeNamespace))
assert.Check(t, util.ContainsAll(output, "Revision", revName2, "deleted", "namespace", commands.FakeNamespace))
assert.Check(t, util.ContainsAll(output, "Revision", revName3, "deleted", "namespace", commands.FakeNamespace))
}

View File

@ -38,7 +38,8 @@ func TestRevision(t *testing.T) {
})
t.Run("describe revision from hello service with print flags", func(t *testing.T) {
test.revisionDescribeWithPrintFlags(t, "hello")
revName := test.findRevision(t, "hello")
test.revisionDescribeWithPrintFlags(t, revName)
})
t.Run("update hello service and increase the count of configuration generation", func(t *testing.T) {
@ -50,7 +51,19 @@ func TestRevision(t *testing.T) {
})
t.Run("delete latest revision from hello service and return no error", func(t *testing.T) {
test.revisionDelete(t, "hello")
revName := test.findRevision(t, "hello")
test.revisionDelete(t, revName)
})
t.Run("delete three revisions with one revision a nonexistent", func(t *testing.T) {
// increase count to 2 revisions
test.serviceUpdate(t, "hello", []string{"--env", "TARGET=kn", "--port", "8888"})
existRevision1 := test.findRevisionByGeneration(t, "hello", 1)
existRevision2 := test.findRevisionByGeneration(t, "hello", 2)
nonexistRevision := "hello-nonexist"
test.revisionMultipleDelete(t, []string{existRevision1, existRevision2, nonexistRevision})
})
t.Run("delete hello service and return no error", func(t *testing.T) {
@ -76,18 +89,31 @@ func (test *e2eTest) revisionListWithService(t *testing.T, serviceNames ...strin
}
}
func (test *e2eTest) revisionDelete(t *testing.T, serviceName string) {
revName := test.findRevision(t, serviceName)
func (test *e2eTest) revisionDelete(t *testing.T, revName string) {
out, err := test.kn.RunWithOpts([]string{"revision", "delete", revName}, runOpts{})
assert.NilError(t, err)
assert.Check(t, util.ContainsAll(out, "Revision", revName, "deleted", "namespace", test.kn.namespace))
}
func (test *e2eTest) revisionDescribeWithPrintFlags(t *testing.T, serviceName string) {
revName := test.findRevision(t, serviceName)
func (test *e2eTest) revisionMultipleDelete(t *testing.T, revisionNames []string) {
existRevision1 := revisionNames[0]
existRevision2 := revisionNames[1]
nonexistRevision := revisionNames[2]
out, err := test.kn.RunWithOpts([]string{"revision", "list"}, runOpts{NoNamespace: false})
assert.NilError(t, err)
assert.Check(t, strings.Contains(out, existRevision1), "Required revision1 does not exist")
assert.Check(t, strings.Contains(out, existRevision2), "Required revision2 does not exist")
out, err = test.kn.RunWithOpts([]string{"revision", "delete", existRevision1, existRevision2, nonexistRevision}, runOpts{NoNamespace: false})
assert.Check(t, util.ContainsAll(out, "Revision", existRevision1, "deleted", "namespace", test.kn.namespace), "Failed to get 'deleted' first revision message")
assert.Check(t, util.ContainsAll(out, "Revision", existRevision2, "deleted", "namespace", test.kn.namespace), "Failed to get 'deleted' second revision message")
assert.Check(t, util.ContainsAll(out, "revisions.serving.knative.dev", nonexistRevision, "not found"), "Failed to get 'not found' error")
}
func (test *e2eTest) revisionDescribeWithPrintFlags(t *testing.T, revName string) {
out, err := test.kn.RunWithOpts([]string{"revision", "describe", revName, "-o=name"}, runOpts{})
assert.NilError(t, err)