Skip to content

Commit 95b96c9

Browse files
committed
add LEK test for composite get
1 parent ef90d56 commit 95b96c9

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

query_test.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,48 @@ func TestQueryComposite(t *testing.T) {
382382
}
383383
}
384384
}
385-
q := table.GetComposite(map[string]any{
386-
"UserID": 67,
387-
"Msg": "second",
388-
}).Range("Time", Greater, times[0]).Index("UserID-Msg-Time-index")
389-
var ws []widget
390-
if err := q.All(ctx, &ws); err != nil {
391-
t.Error(err)
392-
}
393-
if len(ws) != 2 {
394-
t.Error("unexpected length of return:", len(ws))
395-
}
385+
386+
t.Run("Greater+All", func(t *testing.T) {
387+
q := table.GetComposite(map[string]any{
388+
"UserID": 67,
389+
"Msg": "second",
390+
}).Range("Time", Greater, times[0]).Index("UserID-Msg-Time-index")
391+
var ws []widget
392+
if err := q.All(ctx, &ws); err != nil {
393+
t.Error(err)
394+
}
395+
if len(ws) != 2 {
396+
t.Error("unexpected length of return:", len(ws))
397+
}
398+
})
399+
400+
t.Run("iter+LEK", func(t *testing.T) {
401+
q := table.GetComposite(map[string]any{
402+
"UserID": 67,
403+
"Msg": "second",
404+
}).Range("Time", GreaterOrEqual, times[0]).Index("UserID-Msg-Time-index").SearchLimit(1)
405+
itr := q.Iter()
406+
for i := range times {
407+
var w widget
408+
itr.Next(ctx, &w)
409+
if !w.Time.Equal(times[i]) {
410+
t.Error("bad result:", w.Time, "≠", times[i])
411+
}
412+
if itr.Err() != nil {
413+
t.Error("unexpected error", itr.Err())
414+
}
415+
more := itr.Next(ctx, &w)
416+
if more {
417+
t.Error("unexpected more", more)
418+
}
419+
lek, err := itr.LastEvaluatedKey(context.Background())
420+
if err != nil {
421+
t.Error("LEK error", lek)
422+
}
423+
itr = table.GetComposite(map[string]any{
424+
"UserID": 67,
425+
"Msg": "second",
426+
}).StartFrom(lek).Index("UserID-Msg-Time-index").SearchLimit(1).Iter()
427+
}
428+
})
396429
}

0 commit comments

Comments
 (0)