@@ -12,6 +12,7 @@ package resource_test
12
12
import (
13
13
b64 "encoding/base64"
14
14
15
+ "gopkg.in/ini.v1"
15
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
17
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
18
@@ -44,41 +45,62 @@ var _ = Describe("AdminSecret", func() {
44
45
})
45
46
46
47
Context ("Build with defaults" , func () {
47
- BeforeEach (func () {
48
+ It ("creates the necessary admin secret" , func () {
49
+ var decodedUsername []byte
50
+ var decodedPassword []byte
51
+ var err error
52
+
48
53
obj , err := adminSecretBuilder .Build ()
49
54
Expect (err ).NotTo (HaveOccurred ())
50
55
secret = obj .(* corev1.Secret )
51
- })
52
56
53
- It ( "creates the secret with correct name and namespace" , func () {
54
- Expect (secret .Name ).To (Equal (instance .ChildResourceName ("admin" )))
55
- Expect (secret .Namespace ).To (Equal ("a namespace" ))
56
- })
57
+ By ( "creating the secret with correct name and namespace" , func () {
58
+ Expect (secret .Name ).To (Equal (instance .ChildResourceName ("admin" )))
59
+ Expect (secret .Namespace ).To (Equal ("a namespace" ))
60
+ })
57
61
58
- It ( "creates a 'opaque' secret " , func () {
59
- Expect (secret .Type ).To (Equal (corev1 .SecretTypeOpaque ))
60
- })
62
+ By ( "creating a 'opaque' secret " , func () {
63
+ Expect (secret .Type ).To (Equal (corev1 .SecretTypeOpaque ))
64
+ })
61
65
62
- It ( "creates a rabbitmq username that is base64 encoded and 24 characters in length" , func () {
63
- username , ok := secret .Data ["username" ]
64
- Expect (ok ).NotTo (BeFalse ())
65
- decodedUsername , err : = b64 .URLEncoding .DecodeString (string (username ))
66
- Expect (err ).NotTo (HaveOccurred ())
67
- Expect (len (decodedUsername )).To (Equal (24 ))
66
+ By ( "creating a rabbitmq username that is base64 encoded and 24 characters in length" , func () {
67
+ username , ok := secret .Data ["username" ]
68
+ Expect (ok ).NotTo (BeFalse ())
69
+ decodedUsername , err = b64 .URLEncoding .DecodeString (string (username ))
70
+ Expect (err ).NotTo (HaveOccurred ())
71
+ Expect (len (decodedUsername )).To (Equal (24 ))
68
72
69
- })
73
+ })
70
74
71
- It ("creates a rabbitmq password that is base64 encoded and 24 characters in length" , func () {
72
- password , ok := secret .Data ["password" ]
73
- Expect (ok ).NotTo (BeFalse ())
74
- decodedPassword , err := b64 .URLEncoding .DecodeString (string (password ))
75
- Expect (err ).NotTo (HaveOccurred ())
76
- Expect (len (decodedPassword )).To (Equal (24 ))
75
+ By ("creating a rabbitmq password that is base64 encoded and 24 characters in length" , func () {
76
+ password , ok := secret .Data ["password" ]
77
+ Expect (ok ).NotTo (BeFalse ())
78
+ decodedPassword , err = b64 .URLEncoding .DecodeString (string (password ))
79
+ Expect (err ).NotTo (HaveOccurred ())
80
+ Expect (len (decodedPassword )).To (Equal (24 ))
81
+ })
82
+
83
+ By ("creating a default_user.conf file that contains the correct sysctl config format to be parsed by RabbitMQ" , func () {
84
+ defaultUserConf , ok := secret .Data ["default_user.conf" ]
85
+ Expect (ok ).NotTo (BeFalse ())
86
+
87
+ decodedDefaultUserConf , err := b64 .URLEncoding .DecodeString (string (defaultUserConf ))
88
+ Expect (err ).NotTo (HaveOccurred ())
89
+
90
+ cfg , err := ini .Load (decodedDefaultUserConf )
91
+ Expect (err ).NotTo (HaveOccurred ())
92
+
93
+ Expect (cfg .Section ("" ).HasKey ("default_user" )).To (BeTrue ())
94
+ Expect (cfg .Section ("" ).HasKey ("default_pass" )).To (BeTrue ())
95
+
96
+ Expect (cfg .Section ("" ).Key ("default_user" ).Value ()).To (Equal (string (decodedUsername )))
97
+ Expect (cfg .Section ("" ).Key ("default_pass" ).Value ()).To (Equal (string (decodedPassword )))
98
+ })
77
99
})
78
100
})
79
101
80
102
Context ("Update with instance labels" , func () {
81
- BeforeEach ( func () {
103
+ It ( "Updates the secret" , func () {
82
104
instance = rabbitmqv1beta1.RabbitmqCluster {
83
105
ObjectMeta : metav1.ObjectMeta {
84
106
Name : "rabbit-labelled" ,
@@ -102,26 +124,26 @@ var _ = Describe("AdminSecret", func() {
102
124
}
103
125
err := adminSecretBuilder .Update (secret )
104
126
Expect (err ).NotTo (HaveOccurred ())
105
- })
106
127
107
- It ( "adds new labels from the CR" , func () {
108
- testLabels (secret .Labels )
109
- })
128
+ By ( "adding new labels from the CR" , func () {
129
+ testLabels (secret .Labels )
130
+ })
110
131
111
- It ( "restores the default labels" , func () {
112
- labels := secret .Labels
113
- Expect (labels ["app.kubernetes.io/name" ]).To (Equal (instance .Name ))
114
- Expect (labels ["app.kubernetes.io/component" ]).To (Equal ("rabbitmq" ))
115
- Expect (labels ["app.kubernetes.io/part-of" ]).To (Equal ("rabbitmq" ))
116
- })
132
+ By ( "restoring the default labels" , func () {
133
+ labels := secret .Labels
134
+ Expect (labels ["app.kubernetes.io/name" ]).To (Equal (instance .Name ))
135
+ Expect (labels ["app.kubernetes.io/component" ]).To (Equal ("rabbitmq" ))
136
+ Expect (labels ["app.kubernetes.io/part-of" ]).To (Equal ("rabbitmq" ))
137
+ })
117
138
118
- It ("deletes the labels that are removed from the CR" , func () {
119
- Expect (secret .Labels ).NotTo (HaveKey ("this-was-the-previous-label" ))
139
+ By ("deleting the labels that are removed from the CR" , func () {
140
+ Expect (secret .Labels ).NotTo (HaveKey ("this-was-the-previous-label" ))
141
+ })
120
142
})
121
143
})
122
144
123
145
Context ("Update with instance annotations" , func () {
124
- BeforeEach ( func () {
146
+ It ( "updates the secret with the annotations" , func () {
125
147
instance = rabbitmqv1beta1.RabbitmqCluster {
126
148
ObjectMeta : metav1.ObjectMeta {
127
149
Name : "rabbit-labelled" ,
@@ -150,19 +172,19 @@ var _ = Describe("AdminSecret", func() {
150
172
}
151
173
err := adminSecretBuilder .Update (secret )
152
174
Expect (err ).NotTo (HaveOccurred ())
153
- })
154
-
155
- It ("updates secret annotations on admin secret" , func () {
156
- expectedAnnotations := map [string ]string {
157
- "my-annotation" : "i-like-this" ,
158
- "i-was-here-already" : "please-dont-delete-me" ,
159
- "im-here-to-stay.kubernetes.io" : "for-a-while" ,
160
- "kubernetes.io/name" : "should-stay" ,
161
- "kubectl.kubernetes.io/name" : "should-stay" ,
162
- "k8s.io/name" : "should-stay" ,
163
- }
164
175
165
- Expect (secret .Annotations ).To (Equal (expectedAnnotations ))
176
+ By ("updating secret annotations on admin secret" , func () {
177
+ expectedAnnotations := map [string ]string {
178
+ "my-annotation" : "i-like-this" ,
179
+ "i-was-here-already" : "please-dont-delete-me" ,
180
+ "im-here-to-stay.kubernetes.io" : "for-a-while" ,
181
+ "kubernetes.io/name" : "should-stay" ,
182
+ "kubectl.kubernetes.io/name" : "should-stay" ,
183
+ "k8s.io/name" : "should-stay" ,
184
+ }
185
+
186
+ Expect (secret .Annotations ).To (Equal (expectedAnnotations ))
187
+ })
166
188
})
167
189
})
168
190
})
0 commit comments