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

Function TestPrefixQueueUpdateObjectAsJSON

prefix_queue_test.go:376–460  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

374}
375
376func TestPrefixQueueUpdateObjectAsJSON(t *testing.T) {
377 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
378 pq, err := OpenPrefixQueue(file)
379 if err != nil {
380 t.Error(err)
381 }
382 defer pq.Drop()
383
384 type subObject struct {
385 Value *int
386 }
387
388 type object struct {
389 Value int
390 SubObject subObject
391 }
392
393 for i := 1; i <= 10; i++ {
394 obj := object{
395 Value: i,
396 SubObject: subObject{
397 Value: &i,
398 },
399 }
400
401 if _, err = pq.EnqueueObjectAsJSON([]byte("prefix"), obj); err != nil {
402 t.Error(err)
403 }
404 }
405
406 item, err := pq.PeekByIDString("prefix", 3)
407 if err != nil {
408 t.Error(err)
409 }
410
411 oldCompObjVal := 3
412 oldCompObj := object{
413 Value: 3,
414 SubObject: subObject{
415 Value: &oldCompObjVal,
416 },
417 }
418 newCompObjVal := 33
419 newCompObj := object{
420 Value: 33,
421 SubObject: subObject{
422 Value: &newCompObjVal,
423 },
424 }
425
426 var obj object
427 if err := item.ToObjectFromJSON(&obj); err != nil {
428 t.Error(err)
429 }
430
431 if *obj.SubObject.Value != *oldCompObj.SubObject.Value {
432 t.Errorf("Expected object subobject value to be '%+v', got '%+v'", *oldCompObj.SubObject.Value, *obj.SubObject.Value)
433 }

Callers

nothing calls this directly

Calls 6

OpenPrefixQueueFunction · 0.85
PeekByIDStringMethod · 0.80
DropMethod · 0.45
EnqueueObjectAsJSONMethod · 0.45
ToObjectFromJSONMethod · 0.45
UpdateObjectAsJSONMethod · 0.45

Tested by

no test coverage detected