-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add channel metadata conformance tests (#2963)
* Add channel metadata conformance tests * Add channel metadata conformance tests * Add channel metadata conformance tests * Add channel metadata conformance tests * Add channel metadata conformance tests * Rename things properly to state that they are CRD tests * Check channel CRD has label duck.knative.dev/addressable * Use apiextensionsv1beta1 * update-codegen
- v0.43.3
- v0.43.2
- v0.43.1
- v0.43.0
- v0.42.5
- v0.42.4
- v0.42.3
- v0.42.2
- v0.42.1
- v0.42.0
- v0.41.7
- v0.41.6
- v0.41.5
- v0.41.4
- v0.41.3
- v0.41.2
- v0.41.1
- v0.41.0
- v0.40.8
- v0.40.7
- v0.40.6
- v0.40.5
- v0.40.4
- v0.40.3
- v0.40.2
- v0.40.1
- v0.40.0
- v0.39.6
- v0.39.5
- v0.39.4
- v0.39.3
- v0.39.2
- v0.39.1
- v0.39.0
- v0.38.11
- v0.38.10
- v0.38.9
- v0.38.8
- v0.38.7
- v0.38.6
- v0.38.5
- v0.38.4
- v0.38.3
- v0.38.2
- v0.38.1
- v0.38.0
- v0.37.5
- v0.37.4
- v0.37.3
- v0.37.2
- v0.37.1
- v0.37.0
- v0.36.7
- v0.36.6
- v0.36.5
- v0.36.4
- v0.36.3
- v0.36.2
- v0.36.1
- v0.36.0
- v0.35.8
- v0.35.7
- v0.35.6
- v0.35.5
- v0.35.4
- v0.35.3
- v0.35.2
- v0.35.1
- v0.35.0
- v0.34.8
- v0.34.7
- v0.34.6
- v0.34.5
- v0.34.4
- v0.34.3
- v0.34.2
- v0.34.1
- v0.34.0
- v0.33.3
- v0.33.2
- v0.33.1
- v0.33.0
- v0.32.6
- v0.32.5
- v0.32.4
- v0.32.3
- v0.32.2
- v0.32.1
- v0.32.0
- v0.31.2
- v0.31.1
- v0.31.0
- v0.30.3
- v0.30.2
- v0.30.1
- v0.30.0
- v0.29.4
- v0.29.3
- v0.29.2
- v0.29.1
- v0.29.0
- v0.28.4
- v0.28.3
- v0.28.2
- v0.28.1
- v0.28.0
- v0.27.5
- v0.27.4
- v0.27.3
- v0.27.2
- v0.27.1
- v0.27.0
- v0.26.4
- v0.26.3
- v0.26.2
- v0.26.1
- v0.26.0
- v0.25.5
- v0.25.4
- v0.25.3
- v0.25.2
- v0.25.1
- v0.25.0
- v0.24.4
- v0.24.3
- v0.24.2
- v0.24.1
- v0.24.0
- v0.23.5
- v0.23.4
- v0.23.3
- v0.23.2
- v0.23.1
- v0.23.0
- v0.22.3
- v0.22.2
- v0.22.1
- v0.22.0
- v0.21.4
- v0.21.3
- v0.21.2
- v0.21.1
- v0.21.0
- v0.20.4
- v0.20.3
- v0.20.2
- v0.20.1
- v0.20.0
- v0.19.5
- v0.19.4
- v0.19.3
- v0.19.2
- v0.19.1
- v0.19.0
- v0.18.6
- v0.18.5
- v0.18.4
- v0.18.3
- v0.18.2
- v0.18.1
- v0.18.0
- v0.17.9
- v0.17.8
- v0.17.7
- v0.17.6
- v0.17.5
- v0.17.4
- v0.17.3
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.4
- v0.16.3
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.4
- v0.15.3
- v0.15.2
- v0.15.1
- v0.15.0
- knative-v1.16.3
- knative-v1.16.2
- knative-v1.16.1
- knative-v1.16.0
- knative-v1.15.5
- knative-v1.15.4
- knative-v1.15.3
- knative-v1.15.2
- knative-v1.15.1
- knative-v1.15.0
- knative-v1.14.7
- knative-v1.14.6
- knative-v1.14.5
- knative-v1.14.4
- knative-v1.14.3
- knative-v1.14.2
- knative-v1.14.1
- knative-v1.14.0
- knative-v1.13.8
- knative-v1.13.7
- knative-v1.13.6
- knative-v1.13.5
- knative-v1.13.4
- knative-v1.13.3
- knative-v1.13.2
- knative-v1.13.1
- knative-v1.13.0
- knative-v1.12.6
- knative-v1.12.5
- knative-v1.12.4
- knative-v1.12.3
- knative-v1.12.2
- knative-v1.12.1
- knative-v1.12.0
- knative-v1.11.11
- knative-v1.11.10
- knative-v1.11.9
- knative-v1.11.8
- knative-v1.11.7
- knative-v1.11.6
- knative-v1.11.5
- knative-v1.11.4
- knative-v1.11.3
- knative-v1.11.2
- knative-v1.11.1
- knative-v1.11.0
- knative-v1.10.5
- knative-v1.10.4
- knative-v1.10.3
- knative-v1.10.2
- knative-v1.10.1
- knative-v1.10.0
- knative-v1.9.7
- knative-v1.9.6
- knative-v1.9.5
- knative-v1.9.4
- knative-v1.9.3
- knative-v1.9.2
- knative-v1.9.1
- knative-v1.9.0
- knative-v1.8.8
- knative-v1.8.7
- knative-v1.8.6
- knative-v1.8.5
- knative-v1.8.4
- knative-v1.8.3
- knative-v1.8.2
- knative-v1.8.1
- knative-v1.8.0
- knative-v1.7.8
- knative-v1.7.7
- knative-v1.7.6
- knative-v1.7.5
- knative-v1.7.4
- knative-v1.7.3
- knative-v1.7.2
- knative-v1.7.1
- knative-v1.7.0
- knative-v1.6.3
- knative-v1.6.2
- knative-v1.6.1
- knative-v1.6.0
- knative-v1.5.6
- knative-v1.5.5
- knative-v1.5.4
- knative-v1.5.3
- knative-v1.5.2
- knative-v1.5.1
- knative-v1.5.0
- knative-v1.4.2
- knative-v1.4.1
- knative-v1.4.0
- knative-v1.3.3
- knative-v1.3.2
- knative-v1.3.1
- knative-v1.3.0
- knative-v1.2.4
- knative-v1.2.3
- knative-v1.2.2
- knative-v1.2.1
- knative-v1.2.0
- knative-v1.1.4
- knative-v1.1.3
- knative-v1.1.2
- knative-v1.1.1
- knative-v1.1.0
- knative-v1.0.5
- knative-v1.0.4
- knative-v1.0.3
- knative-v1.0.2
- knative-v1.0.1
- knative-v1.0.0
Showing
4 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
// +build e2e | ||
|
||
/* | ||
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 TestChannelCRDMetadata(t *testing.T) { | ||
helpers.ChannelCRDMetadataTestHelperWithChannelTestRunner(t, channelTestRunner, lib.SetupClientOptionNoop) | ||
} |
120 changes: 120 additions & 0 deletions
120
test/conformance/helpers/channel_crd_metadata_test_helper.go
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,120 @@ | ||
/* | ||
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" | ||
|
||
"github.com/pkg/errors" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"knative.dev/eventing/test/lib" | ||
) | ||
|
||
// ChannelCRDMetadataTestHelperWithChannelTestRunner runs the Channel CRD metadata tests for all | ||
// Channel resources in the ChannelTestRunner. | ||
func ChannelCRDMetadataTestHelperWithChannelTestRunner( | ||
t *testing.T, | ||
channelTestRunner lib.ChannelTestRunner, | ||
options ...lib.SetupClientOption, | ||
) { | ||
|
||
channelTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { | ||
client := lib.Setup(st, true, options...) | ||
defer lib.TearDown(client) | ||
|
||
t.Run("Channel is namespaced", func(t *testing.T) { | ||
channelIsNamespaced(st, client, channel) | ||
}) | ||
t.Run("Channel CRD has required label", func(t *testing.T) { | ||
channelCRDHasRequiredLabels(st, client, channel) | ||
}) | ||
t.Run("Channel CRD has required label", func(t *testing.T) { | ||
channelCRDHasProperCategory(st, client, channel) | ||
}) | ||
}) | ||
} | ||
|
||
func channelIsNamespaced(st *testing.T, client *lib.Client, channel metav1.TypeMeta) { | ||
// From spec: Each channel is namespaced | ||
|
||
apiResource, err := getApiResource(client, channel) | ||
if err != nil { | ||
client.T.Fatalf("Error finding server resource for %q: %v", channel, err) | ||
} | ||
if !apiResource.Namespaced { | ||
client.T.Fatalf("%q is not namespace scoped: %v", channel, err) | ||
} | ||
} | ||
|
||
func channelCRDHasRequiredLabels(st *testing.T, 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) | ||
} | ||
} | ||
|
||
func channelCRDHasProperCategory(st *testing.T, client *lib.Client, channel metav1.TypeMeta) { | ||
// From spec: | ||
// Each channel MUST have the following: the category channel | ||
|
||
apiResource, err := getApiResource(client, channel) | ||
if err != nil { | ||
client.T.Fatalf("Error finding server resource for %q: %v", channel, err) | ||
} | ||
found := false | ||
for _, cat := range apiResource.Categories { | ||
if cat == "channel" { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
client.T.Fatalf("Channel CRD %q does not have the category 'channel': %v", channel, err) | ||
} | ||
} | ||
|
||
func getApiResource(client *lib.Client, typeMeta metav1.TypeMeta) (*metav1.APIResource, error) { | ||
gvr, _ := meta.UnsafeGuessKindToResource(typeMeta.GroupVersionKind()) | ||
apiResourceList, err := client.Kube.Kube.Discovery().ServerResourcesForGroupVersion(gvr.GroupVersion().String()) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Unable to list server resources for groupVersion of %q: %v", typeMeta, err) | ||
} | ||
|
||
for _, apiResource := range apiResourceList.APIResources { | ||
if apiResource.Kind == typeMeta.Kind { | ||
return &apiResource, nil | ||
} | ||
} | ||
return nil, errors.Errorf("Unable to find server resource for %q: %v", typeMeta, err) | ||
} |
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