-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add --all option to delete all the revisions
- Loading branch information
1 parent
72aeb1c
commit 26c1697
Showing
7 changed files
with
169 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package revision | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
|
||
clientservingv1 "knative.dev/client/pkg/serving/v1" | ||
"knative.dev/client/pkg/util" | ||
"knative.dev/client/pkg/util/mock" | ||
servingv1 "knative.dev/serving/pkg/apis/serving/v1" | ||
) | ||
|
||
func TestRevisionDeleteAllMock(t *testing.T) { | ||
// New mock client | ||
client := clientservingv1.NewMockKnServiceClient(t) | ||
|
||
// Recording: | ||
r := client.Recorder() | ||
|
||
// Wait for delete event | ||
r.DeleteRevision("foo", mock.Any(), nil) | ||
r.DeleteRevision("bar", mock.Any(), nil) | ||
r.DeleteRevision("baz", mock.Any(), nil) | ||
|
||
revision1 := createMockRevisionWithParams("foo", "svc1", "1", "50", "") | ||
revision2 := createMockRevisionWithParams("bar", "svc1", "1", "50", "") | ||
revision3 := createMockRevisionWithParams("baz", "svc1", "1", "50", "") | ||
revisionList := &servingv1.RevisionList{Items: []servingv1.Revision{*revision1, *revision2, *revision3}} | ||
r.ListRevisions(mock.Any(), revisionList, nil) | ||
|
||
output, err := executeRevisionCommand(client, "delete", "--all") | ||
assert.NilError(t, err) | ||
assert.Assert(t, util.ContainsAll(output, "deleted", "foo", "bar", "baz", "default")) | ||
|
||
r.Validate() | ||
} | ||
|
||
func TestRevisionDeleteCheckErrorForNotFoundRevisionsMock(t *testing.T) { | ||
// New mock client | ||
client := clientservingv1.NewMockKnServiceClient(t) | ||
|
||
// Recording: | ||
r := client.Recorder() | ||
|
||
r.DeleteRevision("foo", mock.Any(), nil) | ||
r.DeleteRevision("bar", mock.Any(), errors.New("revisions.serving.knative.dev \"bar\" not found")) | ||
r.DeleteRevision("baz", mock.Any(), errors.New("revisions.serving.knative.dev \"baz\" not found")) | ||
|
||
output, err := executeRevisionCommand(client, "delete", "foo", "bar", "baz") | ||
if err == nil { | ||
t.Fatal("Expected revision not found error, returned nil") | ||
} | ||
assert.Assert(t, util.ContainsAll(output, "'foo' deleted", "\"bar\" not found", "\"baz\" not found")) | ||
|
||
r.Validate() | ||
} | ||
|
||
func TestRevisionDeleteAllErrorFromArgMock(t *testing.T) { | ||
// New mock client | ||
client := clientservingv1.NewMockKnServiceClient(t) | ||
|
||
_, err := executeRevisionCommand(client, "delete", "foo", "--all") | ||
assert.Error(t, err, "'kn revision delete' with --all flag requires no arguments") | ||
} | ||
|
||
func TestRevisionDeleteAllNoRevisionsMock(t *testing.T) { | ||
// New mock client | ||
client := clientservingv1.NewMockKnServiceClient(t) | ||
|
||
// Recording: | ||
r := client.Recorder() | ||
revisionList := &servingv1.RevisionList{Items: []servingv1.Revision{}} | ||
r.ListRevisions(mock.Any(), revisionList, nil) | ||
|
||
output, err := executeRevisionCommand(client, "delete", "--all") | ||
assert.NilError(t, err) | ||
assert.Assert(t, util.ContainsAll(output, "No", "Revisions", "found")) | ||
|
||
r.Validate() | ||
} | ||
|
||
func TestRevisionDeleteNoNameMock(t *testing.T) { | ||
// New mock client | ||
client := clientservingv1.NewMockKnServiceClient(t) | ||
|
||
// Recording: | ||
r := client.Recorder() | ||
|
||
_, err := executeRevisionCommand(client, "delete") | ||
assert.ErrorContains(t, err, "'kn revision delete' requires one or more revision name") | ||
|
||
r.Validate() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters