Skip to content

Commit 931d4e7

Browse files
author
Peng Zhou
committed
fix test with bug: index out of range [0] with length 0
1 parent 6a7df0e commit 931d4e7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

test/e2e/2_marklogic_cluster_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,17 @@ func TestMarklogicCluster(t *testing.T) {
134134
if err != nil {
135135
t.Fatalf("Failed to install grafana helm chart: %v", err)
136136
}
137-
137+
// Wait for Grafana pod to be ready
138+
time.Sleep(5 * time.Second) // Give some time for Grafana to start
138139
podList := &corev1.PodList{}
139140
if err := client.Resources().List(ctx, podList, func(lo *metav1.ListOptions) {
140141
lo.FieldSelector = "metadata.namespace=" + "grafana"
141142
}); err != nil {
142143
t.Fatal(err)
143144
}
144-
145+
if len(podList.Items) == 0 {
146+
t.Fatal("No Grafana pods found")
147+
}
145148
grafanaPodName := podList.Items[0].Name
146149
err = utils.WaitForPod(ctx, t, client, "grafana", grafanaPodName, 120*time.Second)
147150
if err != nil {
@@ -245,6 +248,10 @@ func TestMarklogicCluster(t *testing.T) {
245248
}); err != nil {
246249
t.Fatal(err)
247250
}
251+
time.Sleep(5 * time.Second) // Wait for Grafana to be fully ready
252+
if len(podList.Items) == 0 {
253+
t.Fatal("No Grafana pods found")
254+
}
248255
grafanaPodName := podList.Items[0].Name
249256
grafanaAdminUser, grafanaAdminPassword, err := utils.GetSecretData(ctx, client, "grafana", "grafana", "admin-user", "admin-password")
250257
if err != nil {
@@ -337,7 +344,7 @@ func TestMarklogicCluster(t *testing.T) {
337344
if err := client.Resources().Get(ctx, "marklogicclusters", mlNamespace, &mlcluster); err != nil {
338345
t.Fatal(err)
339346
}
340-
347+
341348
mlcluster.Spec.MarkLogicGroups[0].Resources = &resources
342349
if err := client.Resources().Update(ctx, &mlcluster); err != nil {
343350
t.Log("Failed to update MarkLogic group resources")

0 commit comments

Comments
 (0)