@@ -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,58 @@ 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 username []byte
50
+ var password []byte
51
+ var ok bool
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
-
58
- It ("creates a 'opaque' secret " , func () {
59
- Expect (secret .Type ).To (Equal (corev1 .SecretTypeOpaque ))
60
- })
61
-
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 ))
68
-
69
- })
70
-
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 ))
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
+ })
61
+
62
+ By ("creating a 'opaque' secret " , func () {
63
+ Expect (secret .Type ).To (Equal (corev1 .SecretTypeOpaque ))
64
+ })
65
+
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 (), "Failed to find a key \" username\" in the generated Secret" )
69
+ decodedUsername , err := b64 .URLEncoding .DecodeString (string (username ))
70
+ Expect (err ).NotTo (HaveOccurred ())
71
+ Expect (len (decodedUsername )).To (Equal (24 ))
72
+ })
73
+
74
+ By ("creating a rabbitmq password that is base64 encoded and 24 characters in length" , func () {
75
+ password , ok = secret .Data ["password" ]
76
+ Expect (ok ).NotTo (BeFalse (), "Failed to find a key \" password\" in the generated Secret" )
77
+ decodedPassword , err := b64 .URLEncoding .DecodeString (string (password ))
78
+ Expect (err ).NotTo (HaveOccurred ())
79
+ Expect (len (decodedPassword )).To (Equal (24 ))
80
+ })
81
+
82
+ By ("creating a default_user.conf file that contains the correct sysctl config format to be parsed by RabbitMQ" , func () {
83
+ defaultUserConf , ok := secret .Data ["default_user.conf" ]
84
+ Expect (ok ).NotTo (BeFalse (), "Failed to find a key \" default_user.conf\" in the generated Secret" )
85
+
86
+ cfg , err := ini .Load (defaultUserConf )
87
+ Expect (err ).NotTo (HaveOccurred ())
88
+
89
+ Expect (cfg .Section ("" ).HasKey ("default_user" )).To (BeTrue ())
90
+ Expect (cfg .Section ("" ).HasKey ("default_pass" )).To (BeTrue ())
91
+
92
+ Expect (cfg .Section ("" ).Key ("default_user" ).Value ()).To (Equal (string (username )))
93
+ Expect (cfg .Section ("" ).Key ("default_pass" ).Value ()).To (Equal (string (password )))
94
+ })
77
95
})
78
96
})
79
97
80
98
Context ("Update with instance labels" , func () {
81
- BeforeEach ( func () {
99
+ It ( "Updates the secret" , func () {
82
100
instance = rabbitmqv1beta1.RabbitmqCluster {
83
101
ObjectMeta : metav1.ObjectMeta {
84
102
Name : "rabbit-labelled" ,
@@ -102,26 +120,26 @@ var _ = Describe("AdminSecret", func() {
102
120
}
103
121
err := adminSecretBuilder .Update (secret )
104
122
Expect (err ).NotTo (HaveOccurred ())
105
- })
106
123
107
- It ( "adds new labels from the CR" , func () {
108
- testLabels (secret .Labels )
109
- })
124
+ By ( "adding new labels from the CR" , func () {
125
+ testLabels (secret .Labels )
126
+ })
110
127
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
- })
128
+ By ( "restoring the default labels" , func () {
129
+ labels := secret .Labels
130
+ Expect (labels ["app.kubernetes.io/name" ]).To (Equal (instance .Name ))
131
+ Expect (labels ["app.kubernetes.io/component" ]).To (Equal ("rabbitmq" ))
132
+ Expect (labels ["app.kubernetes.io/part-of" ]).To (Equal ("rabbitmq" ))
133
+ })
117
134
118
- It ("deletes the labels that are removed from the CR" , func () {
119
- Expect (secret .Labels ).NotTo (HaveKey ("this-was-the-previous-label" ))
135
+ By ("deleting the labels that are removed from the CR" , func () {
136
+ Expect (secret .Labels ).NotTo (HaveKey ("this-was-the-previous-label" ))
137
+ })
120
138
})
121
139
})
122
140
123
141
Context ("Update with instance annotations" , func () {
124
- BeforeEach ( func () {
142
+ It ( "updates the secret with the annotations" , func () {
125
143
instance = rabbitmqv1beta1.RabbitmqCluster {
126
144
ObjectMeta : metav1.ObjectMeta {
127
145
Name : "rabbit-labelled" ,
@@ -150,19 +168,19 @@ var _ = Describe("AdminSecret", func() {
150
168
}
151
169
err := adminSecretBuilder .Update (secret )
152
170
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
171
165
- Expect (secret .Annotations ).To (Equal (expectedAnnotations ))
172
+ By ("updating secret annotations on admin secret" , func () {
173
+ expectedAnnotations := map [string ]string {
174
+ "my-annotation" : "i-like-this" ,
175
+ "i-was-here-already" : "please-dont-delete-me" ,
176
+ "im-here-to-stay.kubernetes.io" : "for-a-while" ,
177
+ "kubernetes.io/name" : "should-stay" ,
178
+ "kubectl.kubernetes.io/name" : "should-stay" ,
179
+ "k8s.io/name" : "should-stay" ,
180
+ }
181
+
182
+ Expect (secret .Annotations ).To (Equal (expectedAnnotations ))
183
+ })
166
184
})
167
185
})
168
186
})
0 commit comments