@@ -17,9 +17,8 @@ limitations under the License.
1717package annotations
1818
1919import (
20- "testing"
21-
2220 . "github.com/onsi/gomega"
21+ "testing"
2322)
2423
2524func TestGetNADAnnotation (t * testing.T ) {
@@ -61,3 +60,42 @@ func TestGetNADAnnotation(t *testing.T) {
6160 })
6261 }
6362}
63+
64+ func TestGetBoolFromAnnotation (t * testing.T ) {
65+ ann := map [string ]string {}
66+ testKey := "service.example.org/key"
67+ var value bool
68+ var exists bool
69+ var err error
70+
71+ t .Run ("" , func (t * testing.T ) {
72+ g := NewWithT (t )
73+
74+ // Case 1: empty annotation map (the key does not exist)
75+ value , exists , err = GetBoolFromAnnotation (ann , testKey )
76+ g .Expect (exists ).To (BeFalse ())
77+ g .Expect (value ).To (BeFalse ())
78+ g .Expect (err ).NotTo (HaveOccurred ())
79+
80+ // Case 2: testKey exists but is not a valid bool
81+ ann [testKey ] = "foo"
82+ value , exists , err = GetBoolFromAnnotation (ann , testKey )
83+ g .Expect (value ).To (BeFalse ())
84+ g .Expect (exists ).To (BeTrue ())
85+ g .Expect (err ).To (HaveOccurred ())
86+
87+ // Case 3: testKey exists and is False
88+ ann [testKey ] = "false"
89+ value , exists , err = GetBoolFromAnnotation (ann , testKey )
90+ g .Expect (value ).To (BeFalse ())
91+ g .Expect (exists ).To (BeTrue ())
92+ g .Expect (err ).ToNot (HaveOccurred ())
93+
94+ // Case 4: testKey exists and is True
95+ ann [testKey ] = "true"
96+ value , exists , err = GetBoolFromAnnotation (ann , testKey )
97+ g .Expect (value ).To (BeTrue ())
98+ g .Expect (exists ).To (BeTrue ())
99+ g .Expect (err ).ToNot (HaveOccurred ())
100+ })
101+ }
0 commit comments