mergeConditionMap() is called and the result is validated.
(t *testing.T)
| 245 | |
| 246 | // mergeConditionMap() is called and the result is validated. |
| 247 | func TestMergeConditionMap(t *testing.T) { |
| 248 | condKeyMap1 := make(ConditionKeyMap) |
| 249 | condKeyMap1.Add("s3:prefix", set.CreateStringSet("hello")) |
| 250 | condMap1 := make(ConditionMap) |
| 251 | condMap1.Add("StringEquals", condKeyMap1) |
| 252 | |
| 253 | condKeyMap2 := make(ConditionKeyMap) |
| 254 | condKeyMap2.Add("s3:prefix", set.CreateStringSet("world")) |
| 255 | condMap2 := make(ConditionMap) |
| 256 | condMap2.Add("StringEquals", condKeyMap2) |
| 257 | |
| 258 | condMap3 := make(ConditionMap) |
| 259 | condMap3.Add("StringNotEquals", condKeyMap2) |
| 260 | |
| 261 | testCases := []struct { |
| 262 | condMap1 ConditionMap |
| 263 | condMap2 ConditionMap |
| 264 | expectedResult string |
| 265 | }{ |
| 266 | // Both arguments are empty. |
| 267 | {make(ConditionMap), make(ConditionMap), `{}`}, |
| 268 | // First argument is empty. |
| 269 | {make(ConditionMap), condMap1, `{"StringEquals":{"s3:prefix":["hello"]}}`}, |
| 270 | // Second argument is empty. |
| 271 | {condMap1, make(ConditionMap), `{"StringEquals":{"s3:prefix":["hello"]}}`}, |
| 272 | // Both arguments are same value. |
| 273 | {condMap1, condMap1, `{"StringEquals":{"s3:prefix":["hello"]}}`}, |
| 274 | // Value of second argument will be merged. |
| 275 | {condMap1, condMap2, `{"StringEquals":{"s3:prefix":["hello","world"]}}`}, |
| 276 | // second argument will be added. |
| 277 | {condMap1, condMap3, `{"StringEquals":{"s3:prefix":["hello"]},"StringNotEquals":{"s3:prefix":["world"]}}`}, |
| 278 | } |
| 279 | |
| 280 | for _, testCase := range testCases { |
| 281 | condMap := mergeConditionMap(testCase.condMap1, testCase.condMap2) |
| 282 | if data, err := json.Marshal(condMap); err != nil { |
| 283 | t.Fatalf("Unable to marshal ConditionKeyMap to JSON, %s", err) |
| 284 | } else { |
| 285 | if string(data) != testCase.expectedResult { |
| 286 | t.Fatalf("case: %+v: expected: %s, got: %s", testCase, testCase.expectedResult, string(data)) |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
nothing calls this directly
no test coverage detected