MCPcopy Create free account
hub / github.com/beeker1121/goque / TestQueueUpdateObject

Function TestQueueUpdateObject

queue_test.go:364–424  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

362}
363
364func TestQueueUpdateObject(t *testing.T) {
365 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
366 q, err := OpenQueue(file)
367 if err != nil {
368 t.Error(err)
369 }
370 defer q.Drop()
371
372 type object struct {
373 Value int
374 }
375
376 for i := 1; i <= 10; i++ {
377 if _, err = q.EnqueueObject(object{i}); err != nil {
378 t.Error(err)
379 }
380 }
381
382 item, err := q.PeekByID(3)
383 if err != nil {
384 t.Error(err)
385 }
386
387 oldCompObj := object{3}
388 newCompObj := object{33}
389
390 var obj object
391 if err := item.ToObject(&obj); err != nil {
392 t.Error(err)
393 }
394
395 if obj != oldCompObj {
396 t.Errorf("Expected object to be '%+v', got '%+v'", oldCompObj, obj)
397 }
398
399 updatedItem, err := q.UpdateObject(item.ID, newCompObj)
400 if err != nil {
401 t.Error(err)
402 }
403
404 if err := updatedItem.ToObject(&obj); err != nil {
405 t.Error(err)
406 }
407
408 if obj != newCompObj {
409 t.Errorf("Expected current object to be '%+v', got '%+v'", newCompObj, obj)
410 }
411
412 newItem, err := q.PeekByID(3)
413 if err != nil {
414 t.Error(err)
415 }
416
417 if err := newItem.ToObject(&obj); err != nil {
418 t.Error(err)
419 }
420
421 if obj != newCompObj {

Callers

nothing calls this directly

Calls 6

OpenQueueFunction · 0.85
DropMethod · 0.45
EnqueueObjectMethod · 0.45
PeekByIDMethod · 0.45
ToObjectMethod · 0.45
UpdateObjectMethod · 0.45

Tested by

no test coverage detected