(t *testing.T)
| 796 | } |
| 797 | |
| 798 | func TestPriorityQueueUpdateObjectAsJSON(t *testing.T) { |
| 799 | file := fmt.Sprintf("test_db_%d", time.Now().UnixNano()) |
| 800 | pq, err := OpenPriorityQueue(file, ASC) |
| 801 | if err != nil { |
| 802 | t.Error(err) |
| 803 | } |
| 804 | defer pq.Drop() |
| 805 | |
| 806 | type subObject struct { |
| 807 | Value *int |
| 808 | } |
| 809 | |
| 810 | type object struct { |
| 811 | Priority uint8 |
| 812 | Value int |
| 813 | SubObject subObject |
| 814 | } |
| 815 | |
| 816 | for p := 0; p <= 4; p++ { |
| 817 | for i := 1; i <= 10; i++ { |
| 818 | obj := object{ |
| 819 | Priority: uint8(p), |
| 820 | Value: i, |
| 821 | SubObject: subObject{ |
| 822 | Value: &i, |
| 823 | }, |
| 824 | } |
| 825 | |
| 826 | if _, err = pq.EnqueueObjectAsJSON(uint8(p), obj); err != nil { |
| 827 | t.Error(err) |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | item, err := pq.PeekByPriorityID(0, 3) |
| 833 | if err != nil { |
| 834 | t.Error(err) |
| 835 | } |
| 836 | |
| 837 | oldCompObjVal := 3 |
| 838 | oldCompObj := object{ |
| 839 | Priority: 0, |
| 840 | Value: 3, |
| 841 | SubObject: subObject{ |
| 842 | Value: &oldCompObjVal, |
| 843 | }, |
| 844 | } |
| 845 | newCompObjVal := 33 |
| 846 | newCompObj := object{ |
| 847 | Priority: 0, |
| 848 | Value: 33, |
| 849 | SubObject: subObject{ |
| 850 | Value: &newCompObjVal, |
| 851 | }, |
| 852 | } |
| 853 | |
| 854 | var obj object |
| 855 | if err := item.ToObjectFromJSON(&obj); err != nil { |
nothing calls this directly
no test coverage detected