66 "net/http"
77 "testing"
88
9+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
911 "github.com/stretchr/testify/assert"
1012 "github.com/stretchr/testify/mock"
1113 "go.mongodb.org/atlas-sdk/v20231115008/admin"
@@ -18,6 +20,57 @@ import (
1820 "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
1921)
2022
23+ func TestShouldCustomRolesSkipReconciling (t * testing.T ) {
24+ tests := []struct {
25+ name string
26+ annotations map [string ]string
27+ expected bool
28+ shouldFail bool
29+ }{
30+ {
31+ name : "No annotations present" ,
32+ annotations : map [string ]string {},
33+ expected : false ,
34+ shouldFail : false ,
35+ },
36+ {
37+ name : "Annotation present but invalid JSON" ,
38+ annotations : map [string ]string {customresource .AnnotationLastSkippedConfiguration : "invalid" },
39+ expected : false ,
40+ shouldFail : true ,
41+ },
42+ {
43+ name : "Annotation present with empty CustomRoles" ,
44+ annotations : map [string ]string {customresource .AnnotationLastSkippedConfiguration : "{\" CustomRoles\" : []}" },
45+ expected : true ,
46+ shouldFail : false ,
47+ },
48+ {
49+ name : "Annotation present with non-empty CustomRoles" ,
50+ annotations : map [string ]string {customresource .AnnotationLastSkippedConfiguration : "{\" CustomRoles\" : [{\" Name\" : \" role1\" }]}" },
51+ expected : false ,
52+ shouldFail : false ,
53+ },
54+ }
55+
56+ for _ , tt := range tests {
57+ t .Run (tt .name , func (t * testing.T ) {
58+ atlasProject := & akov2.AtlasProject {
59+ ObjectMeta : metav1.ObjectMeta {
60+ Annotations : tt .annotations ,
61+ },
62+ }
63+ result , err := shouldCustomRolesSkipReconciling (atlasProject )
64+ if tt .shouldFail {
65+ assert .Error (t , err )
66+ } else {
67+ assert .NoError (t , err )
68+ }
69+ assert .Equal (t , tt .expected , result )
70+ })
71+ }
72+ }
73+
2174func TestEnsureCustomRoles (t * testing.T ) {
2275 testRole := []akov2.CustomRole {
2376 {
0 commit comments