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

Function TestStackUpdateObjectAsJSON

stack_test.go:426–510  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

424}
425
426func TestStackUpdateObjectAsJSON(t *testing.T) {
427 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
428 s, err := OpenStack(file)
429 if err != nil {
430 t.Error(err)
431 }
432 defer s.Drop()
433
434 type subObject struct {
435 Value *int
436 }
437
438 type object struct {
439 Value int
440 SubObject subObject
441 }
442
443 for i := 1; i <= 10; i++ {
444 obj := object{
445 Value: i,
446 SubObject: subObject{
447 Value: &i,
448 },
449 }
450
451 if _, err = s.PushObjectAsJSON(obj); err != nil {
452 t.Error(err)
453 }
454 }
455
456 item, err := s.PeekByID(3)
457 if err != nil {
458 t.Error(err)
459 }
460
461 oldCompObjVal := 3
462 oldCompObj := object{
463 Value: 3,
464 SubObject: subObject{
465 Value: &oldCompObjVal,
466 },
467 }
468 newCompObjVal := 33
469 newCompObj := object{
470 Value: 33,
471 SubObject: subObject{
472 Value: &newCompObjVal,
473 },
474 }
475
476 var obj object
477 if err := item.ToObjectFromJSON(&obj); err != nil {
478 t.Error(err)
479 }
480
481 if *obj.SubObject.Value != *oldCompObj.SubObject.Value {
482 t.Errorf("Expected object subobject value to be '%+v', got '%+v'", *oldCompObj.SubObject.Value, *obj.SubObject.Value)
483 }

Callers

nothing calls this directly

Calls 6

OpenStackFunction · 0.85
PushObjectAsJSONMethod · 0.80
DropMethod · 0.45
PeekByIDMethod · 0.45
ToObjectFromJSONMethod · 0.45
UpdateObjectAsJSONMethod · 0.45

Tested by

no test coverage detected