(t *testing.T)
| 312 | } |
| 313 | |
| 314 | func TestPrefixQueueUpdateObject(t *testing.T) { |
| 315 | file := fmt.Sprintf("test_db_%d", time.Now().UnixNano()) |
| 316 | pq, err := OpenPrefixQueue(file) |
| 317 | if err != nil { |
| 318 | t.Error(err) |
| 319 | } |
| 320 | defer pq.Drop() |
| 321 | |
| 322 | type object struct { |
| 323 | Value int |
| 324 | } |
| 325 | |
| 326 | for i := 1; i <= 10; i++ { |
| 327 | if _, err = pq.EnqueueObject([]byte("prefix"), object{i}); err != nil { |
| 328 | t.Error(err) |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | item, err := pq.PeekByIDString("prefix", 3) |
| 333 | if err != nil { |
| 334 | t.Error(err) |
| 335 | } |
| 336 | |
| 337 | oldCompObj := object{3} |
| 338 | newCompObj := object{33} |
| 339 | |
| 340 | var obj object |
| 341 | if err := item.ToObject(&obj); err != nil { |
| 342 | t.Error(err) |
| 343 | } |
| 344 | |
| 345 | if obj != oldCompObj { |
| 346 | t.Errorf("Expected object to be '%+v', got '%+v'", oldCompObj, obj) |
| 347 | } |
| 348 | |
| 349 | updatedItem, err := pq.UpdateObject([]byte("prefix"), item.ID, newCompObj) |
| 350 | if err != nil { |
| 351 | t.Error(err) |
| 352 | } |
| 353 | |
| 354 | if err := updatedItem.ToObject(&obj); err != nil { |
| 355 | t.Error(err) |
| 356 | } |
| 357 | |
| 358 | if obj != newCompObj { |
| 359 | t.Errorf("Expected current object to be '%+v', got '%+v'", newCompObj, obj) |
| 360 | } |
| 361 | |
| 362 | newItem, err := pq.PeekByIDString("prefix", 3) |
| 363 | if err != nil { |
| 364 | t.Error(err) |
| 365 | } |
| 366 | |
| 367 | if err := newItem.ToObject(&obj); err != nil { |
| 368 | t.Error(err) |
| 369 | } |
| 370 | |
| 371 | if obj != newCompObj { |
nothing calls this directly
no test coverage detected