Skip to content

Commit 6b0a386

Browse files
committed
Add end-to-end test for Broker in different namespace to RMQ
Signed-off-by: Gerhard Lazu <[email protected]>
1 parent 6f6fcc4 commit 6b0a386

File tree

6 files changed

+136
-1
lines changed

6 files changed

+136
-1
lines changed

test/e2e/config/broker/broker.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2021 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package broker
18+
19+
import (
20+
"context"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
kubeclient "knative.dev/pkg/client/injection/kube/client"
24+
"knative.dev/reconciler-test/pkg/environment"
25+
"knative.dev/reconciler-test/pkg/feature"
26+
"knative.dev/reconciler-test/pkg/manifest"
27+
)
28+
29+
func init() {
30+
environment.RegisterPackage(manifest.ImagesLocalYaml()...)
31+
}
32+
33+
func Install(brokerNamespace string) feature.StepFn {
34+
return func(ctx context.Context, t feature.T) {
35+
if _, err := manifest.InstallLocalYaml(ctx, map[string]interface{}{"broker_namespace": brokerNamespace}); err != nil {
36+
t.Fatal(err)
37+
}
38+
}
39+
}
40+
41+
func Uninstall(brokerNamespace string) feature.StepFn {
42+
return func(ctx context.Context, t feature.T) {
43+
if _, err := manifest.InstallLocalYaml(ctx, map[string]interface{}{"broker_namespace": brokerNamespace}); err != nil {
44+
t.Fatal(err)
45+
}
46+
47+
kubeClient := kubeclient.Get(ctx)
48+
49+
if err := kubeClient.CoreV1().Namespaces().Delete(context.Background(), brokerNamespace, metav1.DeleteOptions{}); err != nil {
50+
t.Fatal(err)
51+
}
52+
}
53+
}

test/e2e/config/broker/broker.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 The Knative Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
apiVersion: v1
15+
kind: Namespace
16+
metadata:
17+
name: {{ .broker_namespace }}
18+
---
19+
apiVersion: eventing.knative.dev/v1
20+
kind: Broker
21+
metadata:
22+
name: broker
23+
namespace: {{ .broker_namespace }}
24+
annotations:
25+
eventing.knative.dev/broker.class: RabbitMQBroker
26+
spec:
27+
config:
28+
apiVersion: rabbitmq.com/v1beta1
29+
kind: RabbitmqCluster
30+
name: rabbitmqc
31+
namespace: {{ .namespace }}

test/e2e/config/rabbitmq/cluster.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ kind: RabbitmqCluster
1717
metadata:
1818
name: rabbitmqc
1919
namespace: {{ .namespace }}
20+
annotations:
21+
# We allow any Knative Broker of class RabbitMQBroker in any namespace
22+
# to declare objects against this RabbitMQ cluster
23+
rabbitmq.com/topology-allowed-namespaces: "*"
2024
spec:
2125
replicas: 1
2226
resources:

test/e2e/main_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,12 @@ func TestSourceVhostSetup(t *testing.T) {
163163
env.Test(ctx, t, VHostSourceTest())
164164
env.Finish()
165165
}
166+
167+
func TestBrokerInDifferentNamespaceThanRabbitMQCluster(t *testing.T) {
168+
t.Parallel()
169+
170+
ctx, env := global.Environment()
171+
env.Test(ctx, t, RabbitMQCluster())
172+
env.Test(ctx, t, NamespacedBrokerTest("broker-namespace"))
173+
env.Finish()
174+
}

test/e2e/namespaced_broker_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2021 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"knative.dev/eventing-rabbitmq/test/e2e/config/broker"
21+
22+
"knative.dev/reconciler-test/pkg/feature"
23+
24+
// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
25+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
26+
_ "knative.dev/pkg/system/testing"
27+
)
28+
29+
// MultipleBrokersUsingSingleRabbitMQClusterTest checks that Brokers in different namespaces can use the same RabbitMQ cluster
30+
func NamespacedBrokerTest(namespace string) *feature.Feature {
31+
f := new(feature.Feature)
32+
33+
f.Setup("install Broker in different namespace", broker.Install(namespace))
34+
f.Alpha("Broker and all dependencies - Exchange, Queue & Binding -").Must("be ready", AllGoReady)
35+
f.Teardown("delete Broker namespace and all objects", broker.Uninstall(namespace))
36+
37+
return f
38+
}

test/e2e/rabbitmqcluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const (
4949

5050
// RabbitMQCluster creates a rabbitmq.com/rabbitmqclusters cluster that the
5151
// Broker under test will use. This assumes that the RabbitMQ Operator has
52-
// already been instealled.
52+
// already been installed.
5353
func RabbitMQCluster() *feature.Feature {
5454
f := new(feature.Feature)
5555

0 commit comments

Comments
 (0)