mergeConditionKeyMap() is called and the result is validated.
(t *testing.T)
| 139 | |
| 140 | // mergeConditionKeyMap() is called and the result is validated. |
| 141 | func TestMergeConditionKeyMap(t *testing.T) { |
| 142 | condKeyMap1 := make(ConditionKeyMap) |
| 143 | condKeyMap1.Add("s3:prefix", set.CreateStringSet("hello")) |
| 144 | |
| 145 | condKeyMap2 := make(ConditionKeyMap) |
| 146 | condKeyMap2.Add("s3:prefix", set.CreateStringSet("world")) |
| 147 | |
| 148 | condKeyMap3 := make(ConditionKeyMap) |
| 149 | condKeyMap3.Add("s3:myprefix", set.CreateStringSet("world")) |
| 150 | |
| 151 | testCases := []struct { |
| 152 | condKeyMap1 ConditionKeyMap |
| 153 | condKeyMap2 ConditionKeyMap |
| 154 | expectedResult string |
| 155 | }{ |
| 156 | // Both arguments are empty. |
| 157 | {make(ConditionKeyMap), make(ConditionKeyMap), `{}`}, |
| 158 | // First argument is empty. |
| 159 | {make(ConditionKeyMap), condKeyMap1, `{"s3:prefix":["hello"]}`}, |
| 160 | // Second argument is empty. |
| 161 | {condKeyMap1, make(ConditionKeyMap), `{"s3:prefix":["hello"]}`}, |
| 162 | // Both arguments are same value. |
| 163 | {condKeyMap1, condKeyMap1, `{"s3:prefix":["hello"]}`}, |
| 164 | // Value of second argument will be merged. |
| 165 | {condKeyMap1, condKeyMap2, `{"s3:prefix":["hello","world"]}`}, |
| 166 | // second argument will be added. |
| 167 | {condKeyMap1, condKeyMap3, `{"s3:myprefix":["world"],"s3:prefix":["hello"]}`}, |
| 168 | } |
| 169 | |
| 170 | for _, testCase := range testCases { |
| 171 | condKeyMap := mergeConditionKeyMap(testCase.condKeyMap1, testCase.condKeyMap2) |
| 172 | if data, err := json.Marshal(condKeyMap); err != nil { |
| 173 | t.Fatalf("Unable to marshal ConditionKeyMap to JSON, %s", err) |
| 174 | } else { |
| 175 | if string(data) != testCase.expectedResult { |
| 176 | t.Fatalf("case: %+v: expected: %s, got: %s", testCase, testCase.expectedResult, string(data)) |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // ConditionMap.Add() is called and the result is validated. |
| 183 | func TestConditionMapAdd(t *testing.T) { |
nothing calls this directly
no test coverage detected