-
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.
- Loading branch information
Showing
2 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2021 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 test | ||
|
||
import ( | ||
"gotest.tools/v3/assert" | ||
"knative.dev/client/pkg/util" | ||
) | ||
|
||
// EventtypeCreate creates an eventtype with the given name. | ||
func EventtypeCreate(r *KnRunResultCollector, name, cetype string) { | ||
out := r.KnTest().Kn().Run("eventtype", "create", name, "--type", cetype) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Eventtype", name, "created", "namespace", r.KnTest().Kn().Namespace())) | ||
} | ||
|
||
// EventtypeDelete deletes an eventtype with the given name. | ||
func EventtypeDelete(r *KnRunResultCollector, name string) { | ||
out := r.KnTest().Kn().Run("eventtype", "delete", name) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Eventtype", name, "deleted", "namespace", r.KnTest().Kn().Namespace())) | ||
} | ||
|
||
// EventtypeList verifies listing eventtypes in the given namespace | ||
func EventtypeList(r *KnRunResultCollector, eventtypes ...string) { | ||
out := r.KnTest().Kn().Run("eventtype", "list") | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, eventtypes...)) | ||
} | ||
|
||
// EventtypeDescribe describes an eventtype with the given name. | ||
func EventtypeDescribe(r *KnRunResultCollector, name string) { | ||
out := r.KnTest().Kn().Run("eventtype", "describe", name) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAll(out.Stdout, name, r.KnTest().Kn().Namespace(), "Ready", "BrokerReady")) | ||
} | ||
|
||
func EventtypeCreateWithBrokerSource(r *KnRunResultCollector, name, cetype, broker, source string) { | ||
out := r.KnTest().Kn().Run("eventtype", "create", name, "--type", cetype, "--broker", broker, "--source", source) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Eventtype", name, "created", "namespace", r.KnTest().Kn().Namespace())) | ||
} | ||
|
||
func EventtypeCreateWithSourceError(r *KnRunResultCollector, name, cetype, source string) { | ||
out := r.KnTest().Kn().Run("eventtype", "create", name, "--type", cetype, "--source", source) | ||
r.AssertError(out) | ||
assert.Check(r.T(), util.ContainsAll(out.Stderr, name, "invalid", "control character")) | ||
} |
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,72 @@ | ||
// Copyright © 2022 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 e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
"knative.dev/client/lib/test" | ||
"knative.dev/client/pkg/util" | ||
) | ||
|
||
const ( | ||
testName = "test-eventtype" | ||
testName1 = "test-eventtype-1" | ||
testName2 = "test-eventtype-2" | ||
testName3 = "test-eventtype-3" | ||
testType = "test.type" | ||
testBroker = "test-broker" | ||
testSource = "test.source.com" | ||
testSourceBad = "test.source.com\b" | ||
) | ||
|
||
func TestEventtype(t *testing.T) { | ||
t.Parallel() | ||
it, err := test.NewKnTest() | ||
assert.NilError(t, err) | ||
defer func() { | ||
assert.NilError(t, it.Teardown()) | ||
}() | ||
|
||
r := test.NewKnRunResultCollector(t, it) | ||
defer r.DumpIfFailed() | ||
|
||
t.Log("create eventtype, list, describe, and delete it") | ||
test.EventtypeCreate(r, testName, testType) | ||
test.EventtypeList(r, testName) | ||
test.EventtypeDescribe(r, testName) | ||
test.EventtypeDelete(r, testName) | ||
verifyEventtypeNotfound(r, testName) | ||
|
||
t.Log("create eventtype with broker and source") | ||
test.EventtypeCreateWithBrokerSource(r, testName, testType, testBroker, testSource) | ||
test.EventtypeList(r, testName) | ||
|
||
t.Log("create multiple eventtypes and list them") | ||
test.EventtypeCreate(r, testName1, testType) | ||
test.EventtypeCreate(r, testName2, testType) | ||
test.EventtypeCreate(r, testName3, testType) | ||
test.EventtypeList(r, testName1, testName2, testName3) | ||
|
||
t.Log("create eventtype with invalid source") | ||
test.EventtypeCreateWithSourceError(r, testName, testType, testSourceBad) | ||
} | ||
|
||
func verifyEventtypeNotfound(r *test.KnRunResultCollector, name string) { | ||
out := r.KnTest().Kn().Run("eventtype", "describe", name) | ||
r.AssertError(out) | ||
assert.Check(r.T(), util.ContainsAll(out.Stderr, name, "not found")) | ||
} |