@@ -78,4 +78,71 @@ var _ = Describe("Map Utils Tests", func() {
7878
7979 })
8080
81+ Context ("ContainsKeysWithValues" , func () {
82+
83+ It ("should return true if the second map is empty or nil" , func () {
84+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" }
85+ Expect (maps .ContainsKeysWithValues (m1 , nil )).To (BeTrue ())
86+ Expect (maps .ContainsKeysWithValues (m1 , map [string ]string {})).To (BeTrue ())
87+ Expect (maps .ContainsKeysWithValues [string , string ](nil , nil )).To (BeTrue ())
88+ })
89+
90+ It ("should return true if both maps are identical" , func () {
91+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" }
92+ Expect (maps .ContainsKeysWithValues (m1 , m1 )).To (BeTrue ())
93+ })
94+
95+ It ("should return true if the first map contains all keys and values of the second map" , func () {
96+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" , "baz" : "asdf" }
97+ m2 := map [string ]string {"foo" : "bar" , "baz" : "asdf" }
98+ Expect (maps .ContainsKeysWithValues (m1 , m2 )).To (BeTrue ())
99+
100+ m3 := map [string ]string {"bar" : "baz" }
101+ Expect (maps .ContainsKeysWithValues (m1 , m3 )).To (BeTrue ())
102+ })
103+
104+ It ("should return false if the first map contains all keys but has different values" , func () {
105+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" }
106+ m2 := map [string ]string {"foo" : "baz" , "bar" : "baz" }
107+ Expect (maps .ContainsKeysWithValues (m1 , m2 )).To (BeFalse ())
108+ })
109+
110+ It ("should return false if the first map does not contain all keys of the second map" , func () {
111+ m1 := map [string ]string {"foo" : "bar" }
112+ m2 := map [string ]string {"foo" : "bar" , "bar" : "baz" }
113+ Expect (maps .ContainsKeysWithValues (m1 , m2 )).To (BeFalse ())
114+ })
115+
116+ It ("should work with a custom equality function" , func () {
117+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" }
118+ m2 := map [string ]string {"foo" : "xyz" , "bar" : "mno" }
119+ cmp := func (a , b string ) bool {
120+ return len (a ) == len (b )
121+ }
122+ Expect (maps .ContainsKeysWithValuesFunc (m1 , m2 , cmp )).To (BeTrue ())
123+ })
124+
125+ })
126+
127+ Context ("ContainsKeys" , func () {
128+
129+ It ("should return true if all keys are present" , func () {
130+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" , "baz" : "asdf" }
131+ Expect (maps .ContainsKeys (m1 , "foo" , "bar" )).To (BeTrue ())
132+ })
133+
134+ It ("should return true if no keys are provided" , func () {
135+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" , "baz" : "asdf" }
136+ Expect (maps .ContainsKeys (m1 )).To (BeTrue ())
137+ Expect (maps.ContainsKeys [string , string ](nil )).To (BeTrue ())
138+ })
139+
140+ It ("should return false if any key is missing" , func () {
141+ m1 := map [string ]string {"foo" : "bar" , "bar" : "baz" , "baz" : "asdf" }
142+ Expect (maps .ContainsKeys (m1 , "foo" , "missing" )).To (BeFalse ())
143+ Expect (maps .ContainsKeys (m1 , "missing" )).To (BeFalse ())
144+ })
145+
146+ })
147+
81148})
0 commit comments