@@ -21,9 +21,7 @@ import (
21
21
"fmt"
22
22
"path/filepath"
23
23
"testing"
24
- "time"
25
24
26
- corev1 "k8s.io/api/core/v1"
27
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
26
"k8s.io/apimachinery/pkg/types"
29
27
"k8s.io/client-go/kubernetes/scheme"
59
57
grafanaContainer testcontainers.Container
60
58
externalGrafanaCr * v1beta1.Grafana
61
59
62
- grafanaPort = nat .Port (fmt .Sprint (config .GrafanaHTTPPort )) //nolint
63
- grafanaCredentials = map [string ]string {
64
- "GF_SECURITY_ADMIN_USER" : grafanaUser ,
65
- "GF_SECURITY_ADMIN_PASSWORD" : grafanaPass ,
66
- }
60
+ grafanaPort = nat .Port (fmt .Sprint (config .GrafanaHTTPPort )) //nolint
67
61
)
68
62
69
63
func TestAPIs (t * testing.T ) {
@@ -110,22 +104,12 @@ var _ = BeforeSuite(func() {
110
104
Name : fmt .Sprintf ("%s-%d" , grafanaName , GinkgoRandomSeed ()),
111
105
Image : fmt .Sprintf ("%s:%s" , config .GrafanaImage , config .GrafanaVersion ),
112
106
ExposedPorts : []string {grafanaPort .Port ()},
113
- WaitingFor : wait .ForAll (
114
- wait .ForListeningPort (grafanaPort ),
115
- wait .ForHTTP ("/api/frontend/settings" ).
116
- WithPort (grafanaPort ).
117
- WithBasicAuth (grafanaUser , grafanaPass ).
118
- WithStartupTimeout (8 * time .Second ),
119
- ),
120
- Env : grafanaCredentials ,
107
+ WaitingFor : wait .ForHTTP ("/" ).WithPort (grafanaPort ),
121
108
},
122
109
})
123
110
Expect (err ).NotTo (HaveOccurred ())
124
111
125
- port , err := grafanaContainer .MappedPort (testCtx , grafanaPort )
126
- Expect (err ).NotTo (HaveOccurred ())
127
-
128
- createSharedTestCRs (port .Port ())
112
+ createSharedTestCRs ()
129
113
})
130
114
131
115
var _ = AfterSuite (func () {
@@ -134,18 +118,10 @@ var _ = AfterSuite(func() {
134
118
Expect (testEnv .Stop ()).To (Succeed ())
135
119
})
136
120
137
- func createSharedTestCRs (port string ) {
121
+ func createSharedTestCRs () {
138
122
GinkgoHelper ()
139
123
140
- By ("Creating Configmaps and GrafanaFolder for testing" )
141
- secretCR := & corev1.Secret {
142
- ObjectMeta : metav1.ObjectMeta {
143
- Namespace : "default" ,
144
- Name : "external-credentials" ,
145
- },
146
- StringData : grafanaCredentials ,
147
- }
148
- Expect (k8sClient .Create (testCtx , secretCR )).ToNot (HaveOccurred ())
124
+ By ("Creating GrafanaFolder for testing" )
149
125
folderCR := & v1beta1.GrafanaFolder {
150
126
ObjectMeta : metav1.ObjectMeta {
151
127
Namespace : "default" ,
@@ -173,6 +149,11 @@ func createSharedTestCRs(port string) {
173
149
Client : & v1beta1.GrafanaClient {TimeoutSeconds : & intP },
174
150
},
175
151
}
152
+
153
+ // External Endpoint
154
+ endpoint , err := grafanaContainer .PortEndpoint (testCtx , grafanaPort , "http" )
155
+ Expect (err ).NotTo (HaveOccurred ())
156
+
176
157
external := & v1beta1.Grafana {
177
158
ObjectMeta : metav1.ObjectMeta {
178
159
Namespace : "default" ,
@@ -185,18 +166,12 @@ func createSharedTestCRs(port string) {
185
166
},
186
167
Spec : v1beta1.GrafanaSpec {
187
168
External : & v1beta1.External {
188
- URL : fmt .Sprintf ("http://localhost:%s" , port ),
189
- AdminUser : & corev1.SecretKeySelector {
190
- Key : "GF_SECURITY_ADMIN_USER" ,
191
- LocalObjectReference : corev1.LocalObjectReference {
192
- Name : secretCR .Name ,
193
- },
194
- },
195
- AdminPassword : & corev1.SecretKeySelector {
196
- Key : "GF_SECURITY_ADMIN_PASSWORD" ,
197
- LocalObjectReference : corev1.LocalObjectReference {
198
- Name : secretCR .Name ,
199
- },
169
+ URL : endpoint ,
170
+ },
171
+ Config : map [string ]map [string ]string {
172
+ "security" : {
173
+ "admin_user" : config .DefaultAdminUser ,
174
+ "admin_password" : config .DefaultAdminPassword ,
200
175
},
201
176
},
202
177
Client : & v1beta1.GrafanaClient {TimeoutSeconds : & intP },
@@ -220,7 +195,7 @@ func createSharedTestCRs(port string) {
220
195
IsOpenShift : false ,
221
196
}
222
197
reg := requestFromMeta (external .ObjectMeta )
223
- _ , err : = r .Reconcile (testCtx , reg )
198
+ _ , err = r .Reconcile (testCtx , reg )
224
199
Expect (err ).ToNot (HaveOccurred ())
225
200
226
201
By ("Get External Grafana" )
0 commit comments