(t *testing.T)
| 424 | } |
| 425 | |
| 426 | func 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 | } |
nothing calls this directly
no test coverage detected