|
1 | 1 | package djoemo_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "errors" |
5 | 6 |
|
6 | 7 | "go.uber.org/mock/gomock" |
@@ -238,7 +239,9 @@ var _ = Describe("Global Index", func() { |
238 | 239 | It("should return false and nil if item was not found", func() { |
239 | 240 | key := Key().WithTableName(UserTableName). |
240 | 241 | WithHashKeyName("UUID"). |
241 | | - WithHashKey("uuid") |
| 242 | + WithHashKey("uuid"). |
| 243 | + WithRangeKeyName("AppID"). |
| 244 | + WithRangeKey("appid") |
242 | 245 |
|
243 | 246 | dMock.Should(). |
244 | 247 | Query( |
@@ -276,6 +279,37 @@ var _ = Describe("Global Index", func() { |
276 | 279 | }) |
277 | 280 |
|
278 | 281 | }) |
| 282 | + Describe("GetItemsWithRangeWithContext", func() { |
| 283 | + It("should get items with Hash and Range", func() { |
| 284 | + key := Key().WithTableName(UserTableName). |
| 285 | + WithHashKeyName("UUID"). |
| 286 | + WithHashKey("uuid"). |
| 287 | + WithRangeKeyName("AppID"). |
| 288 | + WithRangeKey("appid") |
| 289 | + |
| 290 | + userDBOutput := []map[string]interface{}{ |
| 291 | + {"UUID": "uuid", "UserName": "name1"}, |
| 292 | + {"UUID": "uuid", "UserName": "name2"}, |
| 293 | + } |
| 294 | + |
| 295 | + dMock.Should(). |
| 296 | + Query( |
| 297 | + dMock.WithTable(key.TableName()), |
| 298 | + dMock.WithIndex(IndexName), |
| 299 | + dMock.WithCondition(*key.HashKeyName(), key.HashKey(), "EQ"), |
| 300 | + dMock.WithCondition(*key.RangeKeyName(), key.RangeKey(), "EQ"), |
| 301 | + dMock.WithQueryOutput(userDBOutput), |
| 302 | + ).Exec() |
| 303 | + |
| 304 | + users := &[]User{} |
| 305 | + found, err := repository.GIndex(IndexName).GetItemsWithRangeWithContext(context.Background(), key, users) |
| 306 | + Expect(err).To(BeNil()) |
| 307 | + Expect(found).To(BeTrue()) |
| 308 | + result := *users |
| 309 | + Expect(len(result)).To(BeEqualTo(2)) |
| 310 | + Expect(result[0].UUID).To(BeEqualTo(userDBOutput[0]["UUID"])) |
| 311 | + }) |
| 312 | + }) |
279 | 313 | }) |
280 | 314 |
|
281 | 315 | Describe("Query Items", func() { |
|
0 commit comments