-
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 unit tests for create, update, list, describe, delete
- Loading branch information
1 parent
0057196
commit ddce35d
Showing
10 changed files
with
284 additions
and
96 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 |
---|---|---|
@@ -1,61 +1,82 @@ | ||
// 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. | ||
/* | ||
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 subscription | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"knative.dev/client/pkg/messaging/v1beta1" | ||
|
||
dynamicfake "knative.dev/client/pkg/dynamic/fake" | ||
"knative.dev/client/pkg/util" | ||
) | ||
|
||
func TestCreateSubscriptionErrorCase(t *testing.T) { | ||
cClient := v1beta1.NewMockKnSubscriptionsClient(t) | ||
dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default") | ||
|
||
cRecorder := cClient.Recorder() | ||
_, err := executeSubscriptionCommand(cClient, "create") | ||
_, err := executeSubscriptionCommand(cClient, dynamicClient, "create") | ||
assert.Error(t, err, "'kn subscription create' requires the subscription name given as single argument") | ||
cRecorder.Validate() | ||
} | ||
|
||
func TestCreateSubscriptionErrorCaseTypeFormat(t *testing.T) { | ||
func TestCreateSubscriptionErrorCaseRequiredChannelFlag(t *testing.T) { | ||
cClient := v1beta1.NewMockKnSubscriptionsClient(t) | ||
dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default") | ||
|
||
cRecorder := cClient.Recorder() | ||
_, err := executeSubscriptionCommand(cClient, "create", "pipe", "--type", "foo::bar") | ||
assert.Error(t, err, "Error: incorrect value 'foo::bar' for '--type', must be in the format 'Group:Version:Kind' or configure an alias in kn config") | ||
_, err := executeSubscriptionCommand(cClient, dynamicClient, "create", "sub0") | ||
assert.Error(t, err, "'kn subscription create' requires the channel reference provided with --channel flag") | ||
cRecorder.Validate() | ||
} | ||
|
||
func TestCreateSubscriptionDefaultSubscription(t *testing.T) { | ||
func TestCreateSubscriptionErrorCaseChannelFormat(t *testing.T) { | ||
cClient := v1beta1.NewMockKnSubscriptionsClient(t) | ||
dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default") | ||
|
||
cRecorder := cClient.Recorder() | ||
cRecorder.CreateSubscription(createSubscription("pipe", nil), nil) | ||
out, err := executeSubscriptionCommand(cClient, "create", "pipe") | ||
assert.NilError(t, err, "subscription should be created") | ||
assert.Assert(t, util.ContainsAll(out, "created", "pipe", "default")) | ||
_, err := executeSubscriptionCommand(cClient, dynamicClient, "create", "sub0", "--channel", "foo::bar") | ||
assert.Error(t, err, "Error: incorrect value 'foo::bar' for '--channel', must be in the format 'Group:Version:Kind:Name' or configure an alias in kn config and refer as: '--channel ALIAS:NAME'") | ||
cRecorder.Validate() | ||
} | ||
|
||
func TestCreateSubscriptionWithTypeFlagInMemorySubscription(t *testing.T) { | ||
func TestCreateSubscription(t *testing.T) { | ||
cClient := v1beta1.NewMockKnSubscriptionsClient(t) | ||
dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default", | ||
createService("ksvc0"), | ||
createBroker("b0"), | ||
createBroker("b1")) | ||
|
||
cRecorder := cClient.Recorder() | ||
cRecorder.CreateSubscription(createSubscription("pipe", &schema.GroupVersionKind{"messaging.knative.dev", "v1beta1", "InMemorySubscription"}), nil) | ||
out, err := executeSubscriptionCommand(cClient, "create", "pipe", "--type", "imcv1beta1") | ||
cRecorder.CreateSubscription(createSubscription("sub0", | ||
"imc0", | ||
"ksvc0", | ||
"b0", | ||
"b1"), | ||
nil) | ||
|
||
out, err := executeSubscriptionCommand(cClient, dynamicClient, "create", "sub0", | ||
"--channel", "imcv1beta1:imc0", | ||
"--subscriber", "ksvc0", | ||
"--reply", "broker:b0", | ||
"--dead-letter-sink", "broker:b1") | ||
assert.NilError(t, err, "subscription should be created") | ||
assert.Assert(t, util.ContainsAll(out, "created", "pipe", "default")) | ||
assert.Assert(t, util.ContainsAll(out, "created", "sub0", "default")) | ||
cRecorder.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
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
Oops, something went wrong.