@@ -101,43 +101,11 @@ func (m *mockDynamoDBClient) queryRequest(input *dynamodb.QueryInput) dynamoDBRe
101101 Items : []map [string ]* dynamodb.AttributeValue {},
102102 }
103103
104- // Required filters
105104 hashValue := * input .KeyConditions [hashKey ].AttributeValueList [0 ].S
106-
107- // Optional filters
108- var (
109- rangeValueFilter []byte
110- rangeValueFilterType string
111- valueFilter []byte
112- valueFilterType * string
113- )
114- if c , ok := input .KeyConditions [rangeKey ]; ok {
115- rangeValueFilter = c .AttributeValueList [0 ].B
116- rangeValueFilterType = * c .ComparisonOperator
117- }
118- if c , ok := input .KeyConditions [valueKey ]; ok {
119- valueFilter = c .AttributeValueList [0 ].B
120- valueFilterType = c .ComparisonOperator
121- }
122-
123- // Filter by HashValue, RangeValue and Value if it exists
124105 items := m .tables [* input .TableName ].items [hashValue ]
125- for _ , item := range items {
126- rangeValue := item [rangeKey ].B
127- if rangeValueFilterType == dynamodb .ComparisonOperatorGe && bytes .Compare (rangeValue , rangeValueFilter ) < 0 {
128- continue
129- }
130- if rangeValueFilterType == dynamodb .ComparisonOperatorBeginsWith && ! bytes .HasPrefix (rangeValue , rangeValueFilter ) {
131- continue
132- }
133-
134- if item [valueKey ] != nil {
135- value := item [valueKey ].B
136- if valueFilter != nil && * valueFilterType == dynamodb .ComparisonOperatorEq && ! bytes .Equal (value , valueFilter ) {
137- continue
138- }
139- }
140106
107+ // TODO we should also filter by range value
108+ for _ , item := range items {
141109 result .Items = append (result .Items , item )
142110 }
143111
@@ -202,136 +170,6 @@ func TestDynamoDBClient(t *testing.T) {
202170 }
203171}
204172
205- func TestDynamoDBClientQueryPages (t * testing.T ) {
206- dynamoDB := newMockDynamoDB (0 , 0 )
207- client := awsStorageClient {
208- DynamoDB : dynamoDB ,
209- queryRequestFn : dynamoDB .queryRequest ,
210- }
211-
212- entries := []IndexEntry {
213- {
214- TableName : "table" ,
215- HashValue : "foo" ,
216- RangeValue : []byte ("bar:1" ),
217- Value : []byte ("10" ),
218- },
219- {
220- TableName : "table" ,
221- HashValue : "foo" ,
222- RangeValue : []byte ("bar:2" ),
223- Value : []byte ("20" ),
224- },
225- {
226- TableName : "table" ,
227- HashValue : "foo" ,
228- RangeValue : []byte ("bar:3" ),
229- Value : []byte ("30" ),
230- },
231- {
232- TableName : "table" ,
233- HashValue : "foo" ,
234- RangeValue : []byte ("baz:1" ),
235- Value : []byte ("10" ),
236- },
237- {
238- TableName : "table" ,
239- HashValue : "foo" ,
240- RangeValue : []byte ("baz:2" ),
241- Value : []byte ("20" ),
242- },
243- {
244- TableName : "table" ,
245- HashValue : "flip" ,
246- RangeValue : []byte ("bar:1" ),
247- Value : []byte ("abc" ),
248- },
249- {
250- TableName : "table" ,
251- HashValue : "flip" ,
252- RangeValue : []byte ("bar:2" ),
253- Value : []byte ("abc" ),
254- },
255- {
256- TableName : "table" ,
257- HashValue : "flip" ,
258- RangeValue : []byte ("bar:3" ),
259- Value : []byte ("abc" ),
260- },
261- }
262-
263- tests := []struct {
264- name string
265- entry IndexEntry
266- want []IndexEntry
267- }{
268- {
269- "check HashValue only" ,
270- IndexEntry {
271- TableName : "table" ,
272- HashValue : "flip" ,
273- },
274- []IndexEntry {entries [5 ], entries [6 ], entries [7 ]},
275- },
276- {
277- "check RangeValueStart" ,
278- IndexEntry {
279- TableName : "table" ,
280- HashValue : "foo" ,
281- RangeValueStart : []byte ("bar:2" ),
282- },
283- []IndexEntry {entries [1 ], entries [2 ], entries [3 ], entries [4 ]},
284- },
285- {
286- "check RangeValuePrefix" ,
287- IndexEntry {
288- TableName : "table" ,
289- HashValue : "foo" ,
290- RangeValuePrefix : []byte ("baz:" ),
291- },
292- []IndexEntry {entries [3 ], entries [4 ]},
293- },
294- {
295- "check ValueEqual" ,
296- IndexEntry {
297- TableName : "table" ,
298- HashValue : "foo" ,
299- RangeValuePrefix : []byte ("bar" ),
300- ValueEqual : []byte ("20" ),
301- },
302- []IndexEntry {entries [1 ]},
303- },
304- }
305-
306- batch := client .NewWriteBatch ()
307- for _ , entry := range entries {
308- batch .Add (entry .TableName , entry .HashValue , entry .RangeValue , entry .Value )
309- }
310- dynamoDB .createTable ("table" )
311-
312- err := client .BatchWrite (context .Background (), batch )
313- require .NoError (t , err )
314-
315- for _ , tt := range tests {
316- t .Run (tt .name , func (t * testing.T ) {
317- var have []IndexEntry
318- err := client .QueryPages (context .Background (), tt .entry , func (read ReadBatch , lastPage bool ) bool {
319- for i := 0 ; i < read .Len (); i ++ {
320- have = append (have , IndexEntry {
321- TableName : tt .entry .TableName ,
322- HashValue : tt .entry .HashValue ,
323- RangeValue : read .RangeValue (i ),
324- Value : read .Value (i ),
325- })
326- }
327- return ! lastPage
328- })
329- require .NoError (t , err )
330- require .Equal (t , tt .want , have )
331- })
332- }
333- }
334-
335173func TestAWSConfigFromURL (t * testing.T ) {
336174 for _ , tc := range []struct {
337175 url string
0 commit comments