Skip to content

Commit

Permalink
Added e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasgun committed Feb 23, 2022
1 parent 6c1bcf8 commit 41aa5ea
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/test/eventtype.go
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"))
}
75 changes: 75 additions & 0 deletions test/e2e/eventtype_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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.

//go:build e2e && !serving
// +build e2e,!serving

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"))
}

0 comments on commit 41aa5ea

Please sign in to comment.