MCPcopy
hub / github.com/minio/minio-go / TestConditionMapAdd

Function TestConditionMapAdd

pkg/policy/bucket-policy-condition_test.go:183–215  ·  view source on GitHub ↗

ConditionMap.Add() is called and the result is validated.

(t *testing.T)

Source from the content-addressed store, hash-verified

181
182// ConditionMap.Add() is called and the result is validated.
183func TestConditionMapAdd(t *testing.T) {
184 condMap := make(ConditionMap)
185
186 condKeyMap1 := make(ConditionKeyMap)
187 condKeyMap1.Add("s3:prefix", set.CreateStringSet("hello"))
188
189 condKeyMap2 := make(ConditionKeyMap)
190 condKeyMap2.Add("s3:prefix", set.CreateStringSet("hello", "world"))
191
192 testCases := []struct {
193 key string
194 value ConditionKeyMap
195 expectedResult string
196 }{
197 // Add new key and value.
198 {"StringEquals", condKeyMap1, `{"StringEquals":{"s3:prefix":["hello"]}}`},
199 // Add existing key and value.
200 {"StringEquals", condKeyMap1, `{"StringEquals":{"s3:prefix":["hello"]}}`},
201 // Add existing key and not value.
202 {"StringEquals", condKeyMap2, `{"StringEquals":{"s3:prefix":["hello","world"]}}`},
203 }
204
205 for _, testCase := range testCases {
206 condMap.Add(testCase.key, testCase.value)
207 if data, err := json.Marshal(condMap); err != nil {
208 t.Fatalf("Unable to marshal ConditionKeyMap to JSON, %s", err)
209 } else {
210 if string(data) != testCase.expectedResult {
211 t.Fatalf("case: %+v: expected: %s, got: %s", testCase, testCase.expectedResult, string(data))
212 }
213 }
214 }
215}
216
217// ConditionMap.Remove() is called and the result is validated.
218func TestConditionMapRemove(t *testing.T) {

Callers

nothing calls this directly

Calls 3

CreateStringSetFunction · 0.92
MarshalMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected