-
Notifications
You must be signed in to change notification settings - Fork 587
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 #3319
Changes from all commits
e9133e3
6c310ee
15cafa9
1cd5601
6271e51
7a4c038
040361e
c3b9953
c09a0d3
0c4f116
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,16 @@ import ( | |
"knative.dev/eventing/test/lib" | ||
) | ||
|
||
var channelLabels = map[string]string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
"messaging.knative.dev/subscribable": "true", | ||
"duck.knative.dev/addressable": "true", | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have constants for those labels? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. none that I know of, lemme know if you know them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't found any so I created: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. subscribable is here: |
||
} | ||
|
||
// ChannelCRDMetadataTestHelperWithChannelTestRunner runs the Channel CRD metadata tests for all | ||
// Channel resources in the ChannelTestRunner. | ||
// Channel resources in the ComponentsTestRunner. | ||
func ChannelCRDMetadataTestHelperWithChannelTestRunner( | ||
t *testing.T, | ||
channelTestRunner lib.ChannelTestRunner, | ||
channelTestRunner lib.ComponentsTestRunner, | ||
options ...lib.SetupClientOption, | ||
) { | ||
|
||
|
@@ -41,7 +46,7 @@ func ChannelCRDMetadataTestHelperWithChannelTestRunner( | |
channelIsNamespaced(st, client, channel) | ||
}) | ||
t.Run("Channel CRD has required label", func(t *testing.T) { | ||
channelCRDHasRequiredLabels(st, client, channel) | ||
channelCRDHasRequiredLabels(client, channel) | ||
}) | ||
t.Run("Channel CRD has required label", func(t *testing.T) { | ||
channelCRDHasProperCategory(st, client, channel) | ||
|
@@ -61,27 +66,13 @@ func channelIsNamespaced(st *testing.T, client *lib.Client, channel metav1.TypeM | |
} | ||
} | ||
|
||
func channelCRDHasRequiredLabels(st *testing.T, client *lib.Client, channel metav1.TypeMeta) { | ||
func channelCRDHasRequiredLabels(client *lib.Client, channel metav1.TypeMeta) { | ||
// From spec: | ||
// Each channel MUST have the following: | ||
// label of messaging.knative.dev/subscribable: "true" | ||
// label of duck.knative.dev/addressable: "true" | ||
|
||
gvr, _ := meta.UnsafeGuessKindToResource(channel.GroupVersionKind()) | ||
crdName := gvr.Resource + "." + gvr.Group | ||
|
||
crd, err := client.Apiextensions.CustomResourceDefinitions().Get(crdName, metav1.GetOptions{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
}) | ||
if err != nil { | ||
client.T.Fatalf("Unable to find CRD for %q: %v", channel, err) | ||
} | ||
if crd.Labels["messaging.knative.dev/subscribable"] != "true" { | ||
client.T.Fatalf("Channel CRD doesn't have the label 'messaging.knative.dev/subscribable=true' %q: %v", channel, err) | ||
} | ||
if crd.Labels["duck.knative.dev/addressable"] != "true" { | ||
client.T.Fatalf("Channel CRD doesn't have the label 'duck.knative.dev/addressable=true' %q: %v", channel, err) | ||
} | ||
validateRequiredLabels(client, channel, channelLabels) | ||
} | ||
|
||
func channelCRDHasProperCategory(st *testing.T, client *lib.Client, channel metav1.TypeMeta) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
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 ( | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
testlib "knative.dev/eventing/test/lib" | ||
) | ||
|
||
func validateRequiredLabels(client *testlib.Client, object metav1.TypeMeta, labels map[string]string) { | ||
for k, v := range labels { | ||
if !objectHasRequiredLabel(client, object, k, v) { | ||
client.T.Fatalf("can't find label '%s=%s' in CRD %q", k, v, object) | ||
} | ||
} | ||
} | ||
|
||
func objectHasRequiredLabel(client *testlib.Client, object metav1.TypeMeta, key string, value string) bool { | ||
gvr, _ := meta.UnsafeGuessKindToResource(object.GroupVersionKind()) | ||
crdName := gvr.Resource + "." + gvr.Group | ||
|
||
crd, err := client.Apiextensions.CustomResourceDefinitions().Get(crdName, metav1.GetOptions{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
}) | ||
if err != nil { | ||
client.T.Errorf("error while getting %q:%v", object, err) | ||
} | ||
return crd.Labels[key] == value | ||
} |
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" | ||
"knative.dev/eventing/test/lib" | ||
) | ||
|
||
var sourceLabels = map[string]string{ | ||
"duck.knative.dev/source": "true", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as before, don't we have constants? |
||
} | ||
|
||
func SourceCRDMetadataTestHelperWithChannelTestRunner( | ||
t *testing.T, | ||
sourceTestRunner lib.ComponentsTestRunner, | ||
options ...lib.SetupClientOption, | ||
) { | ||
|
||
sourceTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, source metav1.TypeMeta) { | ||
client := lib.Setup(st, true, options...) | ||
defer lib.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) | ||
}) | ||
|
||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,19 @@ import ( | |
"knative.dev/eventing/test/lib" | ||
) | ||
|
||
var channelTestRunner lib.ChannelTestRunner | ||
var channelTestRunner lib.ComponentsTestRunner | ||
var sourcesTestRunner lib.ComponentsTestRunner | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those 2 are somewhat related and deserve to be grouped, either as var (
channelTestRunner lib.ComponentsTestRunner
sourcesTestRunner lib.ComponentsTestRunner
) or var channelTestRunner, sourcesTestRunner lib.ComponentsTestRunner |
||
var brokerClass string | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(func() int { | ||
test.InitializeEventingFlags() | ||
channelTestRunner = lib.ChannelTestRunner{ | ||
ChannelFeatureMap: lib.ChannelFeatureMap, | ||
ChannelsToTest: test.EventingFlags.Channels, | ||
channelTestRunner = lib.ComponentsTestRunner{ | ||
ComponentFeatureMap: lib.ChannelFeatureMap, | ||
ComponentsToTest: test.EventingFlags.Channels, | ||
} | ||
sourcesTestRunner = lib.ComponentsTestRunner{ | ||
ComponentsToTest: test.EventingFlags.Sources, | ||
} | ||
brokerClass = test.EventingFlags.BrokerClass | ||
|
||
|
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" | ||
"knative.dev/eventing/test/lib" | ||
) | ||
|
||
func TestSourceCRDMetadata(t *testing.T) { | ||
helpers.SourceCRDMetadataTestHelperWithChannelTestRunner(t, sourcesTestRunner, lib.SetupClientOptionNoop) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wanna change this great (IMO) rename here as well:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, will do