ConditionMap.Add() is called and the result is validated.
(t *testing.T)
| 181 | |
| 182 | // ConditionMap.Add() is called and the result is validated. |
| 183 | func 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. |
| 218 | func TestConditionMapRemove(t *testing.T) { |
nothing calls this directly
no test coverage detected