-
Notifications
You must be signed in to change notification settings - Fork 62
/
exchange_types_test.go
89 lines (83 loc) · 2.45 KB
/
exchange_types_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package v1beta1
import (
"context"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
)
var _ = Describe("Exchange spec", func() {
var (
namespace = "default"
ctx = context.Background()
)
It("creates a exchange with default settings", func() {
expectedSpec := ExchangeSpec{
Name: "test-exchange",
Vhost: "/",
Durable: false,
AutoDelete: false,
Type: "direct",
RabbitmqClusterReference: RabbitmqClusterReference{
Name: "some-cluster",
},
}
exchange := Exchange{
ObjectMeta: metav1.ObjectMeta{
Name: "test-exchange",
Namespace: namespace,
},
Spec: ExchangeSpec{
Name: "test-exchange",
RabbitmqClusterReference: RabbitmqClusterReference{
Name: "some-cluster",
},
},
}
Expect(k8sClient.Create(ctx, &exchange)).To(Succeed())
fetchedExchange := &Exchange{}
Expect(k8sClient.Get(ctx, types.NamespacedName{
Name: exchange.Name,
Namespace: exchange.Namespace,
}, fetchedExchange)).To(Succeed())
Expect(fetchedExchange.Spec).To(Equal(expectedSpec))
})
It("creates a exchange with configurations", func() {
exchange := Exchange{
ObjectMeta: metav1.ObjectMeta{
Name: "random-exchange",
Namespace: namespace,
},
Spec: ExchangeSpec{
Name: "test-exchange",
Vhost: "/hello",
Type: "fanout",
Durable: true,
AutoDelete: true,
Arguments: &runtime.RawExtension{
Raw: []byte(`{"alternative-exchange":"alternative-name"}`),
},
RabbitmqClusterReference: RabbitmqClusterReference{
Name: "random-cluster",
},
},
}
Expect(k8sClient.Create(ctx, &exchange)).To(Succeed())
fetchedExchange := &Exchange{}
Expect(k8sClient.Get(ctx, types.NamespacedName{
Name: exchange.Name,
Namespace: exchange.Namespace,
}, fetchedExchange)).To(Succeed())
Expect(fetchedExchange.Spec.Name).To(Equal("test-exchange"))
Expect(fetchedExchange.Spec.Vhost).To(Equal("/hello"))
Expect(fetchedExchange.Spec.Type).To(Equal("fanout"))
Expect(fetchedExchange.Spec.Durable).To(BeTrue())
Expect(fetchedExchange.Spec.AutoDelete).To(BeTrue())
Expect(fetchedExchange.Spec.RabbitmqClusterReference).To(Equal(
RabbitmqClusterReference{
Name: "random-cluster",
}))
Expect(fetchedExchange.Spec.Arguments.Raw).To(Equal([]byte(`{"alternative-exchange":"alternative-name"}`)))
})
})