diff --git a/lib/test/eventtype.go b/lib/test/eventtype.go new file mode 100644 index 0000000000..8c2cb48439 --- /dev/null +++ b/lib/test/eventtype.go @@ -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")) +} diff --git a/test/e2e/eventtype_test.go b/test/e2e/eventtype_test.go new file mode 100644 index 0000000000..cc42a7016f --- /dev/null +++ b/test/e2e/eventtype_test.go @@ -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")) +}