Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sources metadata conformance test #3363

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions test/conformance/helpers/source_crd_metadata_test_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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 helpers

import (
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testlib "knative.dev/eventing/test/lib"
)

var sourceLabels = map[string]string{
"duck.knative.dev/source": "true",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until we have knative/pkg#1424 available, let's go w/ this

}

func SourceCRDMetadataTestHelperWithChannelTestRunner(
t *testing.T,
sourceTestRunner testlib.ComponentsTestRunner,
options ...testlib.SetupClientOption,
) {

sourceTestRunner.RunTests(t, testlib.FeatureBasic, func(st *testing.T, source metav1.TypeMeta) {
client := testlib.Setup(st, true, options...)
defer testlib.TearDown(client)

// From spec:
// Each source MUST have the following:
// label of duck.knative.dev/source: "true"
t.Run("Source CRD has required label", func(t *testing.T) {
validateRequiredLabels(client, source, sourceLabels)
})

})
}
4 changes: 4 additions & 0 deletions test/conformance/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
)

var channelTestRunner testlib.ComponentsTestRunner
var sourcesTestRunner testlib.ComponentsTestRunner
var brokerClass string

func TestMain(m *testing.M) {
Expand All @@ -36,6 +37,9 @@ func TestMain(m *testing.M) {
ComponentFeatureMap: testlib.ChannelFeatureMap,
ComponentsToTest: test.EventingFlags.Channels,
}
sourcesTestRunner = testlib.ComponentsTestRunner{
ComponentsToTest: test.EventingFlags.Sources,
}
brokerClass = test.EventingFlags.BrokerClass

// Any tests may SetupZipkinTracing, it will only actually be done once. This should be the ONLY
Expand Down
28 changes: 28 additions & 0 deletions test/conformance/source_crd_metadata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
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 conformance

import (
"testing"

"knative.dev/eventing/test/conformance/helpers"
testlib "knative.dev/eventing/test/lib"
)

func TestSourceCRDMetadata(t *testing.T) {
helpers.SourceCRDMetadataTestHelperWithChannelTestRunner(t, sourcesTestRunner, testlib.SetupClientOptionNoop)
}
2 changes: 1 addition & 1 deletion test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ initialize $@ --skip-istio-addon
install_mt_broker || fail_test "Could not install MT Channel Based Broker"

echo "Running tests with Multi Tenant Channel Based Broker"
go_test_e2e -timeout=20m -parallel=12 ./test/e2e ./test/conformance -brokerclass=MTChannelBasedBroker -channels=messaging.knative.dev/v1beta1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel || fail_test
go_test_e2e -timeout=20m -parallel=12 ./test/e2e ./test/conformance -brokerclass=MTChannelBasedBroker -channels=messaging.knative.dev/v1beta1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel -sources=sources.knative.dev/v1alpha2:ApiServerSource,sources.knative.dev/v1alpha2:ContainerSource,sources.knative.dev/v1alpha2:PingSource || fail_test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w00t!


success
4 changes: 4 additions & 0 deletions test/e2e_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const (
BrokerUsage = "Which brokerclass to test, requires the proper Broker " +
"implementation to have been installed, and only one value. brokerclass " +
"must be (for now) 'MTChannelBasedBroker'."
SourceUsage = "The names of the source type metas, separated by comma. " +
"Example: \"sources.knative.dev/v1alpha1:ApiServerSource," +
"sources.knative.dev/v1alpha1:PingSource\"."
)

// EventingFlags holds the command line flags specific to knative/eventing.
Expand All @@ -46,6 +49,7 @@ func InitializeEventingFlags() {

flag.Var(&EventingFlags.Channels, "channels", ChannelUsage)
flag.StringVar(&EventingFlags.BrokerClass, "brokerclass", "MTChannelBasedBroker", BrokerUsage)
flag.Var(&EventingFlags.Sources, "sources", SourceUsage)
flag.Parse()

// If no channel is passed through the flag, initialize it as the DefaultChannel.
Expand Down
20 changes: 2 additions & 18 deletions test/flags/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package flags

import (
"fmt"
"log"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -33,26 +32,11 @@ func (channels *Channels) String() string {

// Set appends the input string to Channels.
func (channels *Channels) Set(value string) error {
for _, channel := range strings.Split(value, ",") {
channel := strings.TrimSpace(channel)
split := strings.Split(channel, ":")
if len(split) != 2 {
log.Fatalf("The given Channel name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", channel)
}
tm := metav1.TypeMeta{
APIVersion: split[0],
Kind: split[1],
}
if !isValidChannel(tm.Kind) {
log.Fatalf("The given Channel name %q is invalid, tests cannot be run.\n", channel)
}

*channels = append(*channels, tm)
}
*channels = csvToObjects(value, isValidChannel)
return nil
}

// Check if the channel name is valid.
// Check if the channel kind is valid.
func isValidChannel(channel string) bool {
return strings.HasSuffix(channel, "Channel")
}
1 change: 1 addition & 0 deletions test/flags/eventing_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ package flags
type EventingEnvironmentFlags struct {
BrokerClass string
Channels
Sources
}
47 changes: 47 additions & 0 deletions test/flags/parsing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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 flags

import (
"log"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type Validator func(string) bool

func csvToObjects(csvObjects string, validator Validator) []metav1.TypeMeta {
result := make([]metav1.TypeMeta, 0, 5)
for _, object := range strings.Split(csvObjects, ",") {
object := strings.TrimSpace(object)
split := strings.Split(object, ":")
if len(split) != 2 {
log.Fatalf("The given object name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", object)
}
tm := metav1.TypeMeta{
APIVersion: split[0],
Kind: split[1],
}
if !validator(tm.Kind) {
log.Fatalf("The given object name %q is invalid, tests cannot be run.\n", object)
}

result = append(result, tm)
}
return result
}
42 changes: 42 additions & 0 deletions test/flags/sources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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 flags

import (
"fmt"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Sources holds the Sources we want to run test against.
type Sources []metav1.TypeMeta

func (sources *Sources) String() string {
return fmt.Sprint(*sources)
}

// Set appends the input string to Sources.
func (sources *Sources) Set(value string) error {
*sources = csvToObjects(value, isValidSource)
return nil
}

// Check if the Source kind is valid.
func isValidSource(source string) bool {
return strings.HasSuffix(source, "Source")
}