Skip to content

Commit ad90d46

Browse files
committed
Test: removeMissingCRs
1 parent 133ecd7 commit ad90d46

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package controllers
2+
3+
import (
4+
"testing"
5+
6+
v1beta1 "github.com/grafana/grafana-operator/v5/api/v1beta1"
7+
"github.com/stretchr/testify/assert"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
)
10+
11+
func TestRemoveMissingCRs(t *testing.T) {
12+
statusList := v1beta1.NamespacedResourceList{
13+
"default/dashboard/present",
14+
"default/dashboard/missing",
15+
"other/dashboard/missing",
16+
}
17+
18+
dashboards := v1beta1.GrafanaDashboardList{
19+
Items: []v1beta1.GrafanaDashboard{
20+
{
21+
ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "present"},
22+
},
23+
{
24+
ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "unrelated-dashboard"},
25+
},
26+
},
27+
}
28+
29+
t.Run("secureJsonData is preserved", func(t *testing.T) {
30+
assert.Len(t, statusList, 3, "Sanity check")
31+
32+
updateStatus := false
33+
removeMissingCRs(&statusList, &dashboards, &updateStatus)
34+
35+
assert.True(t, updateStatus, "Entries were removed, status needs to be updated but was not")
36+
assert.Len(t, statusList, 1)
37+
38+
assert.NotContains(t, statusList, "default/dashboard/missing")
39+
assert.NotContains(t, statusList, "other/dashboard/missing")
40+
41+
found, _ := statusList.Find("default", "unrelated-dashboard")
42+
assert.False(t, found, "Dashboard is not in status and should not be")
43+
})
44+
}

0 commit comments

Comments
 (0)