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

Function TestStackPushPopPointerJSON

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

Source from the content-addressed store, hash-verified

120}
121
122func TestStackPushPopPointerJSON(t *testing.T) {
123 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
124 q, err := OpenStack(file)
125 if err != nil {
126 t.Error(err)
127 }
128 defer q.Drop()
129
130 type subObject struct {
131 Value *int
132 }
133
134 type object struct {
135 Value int
136 SubObject subObject
137 }
138
139 val := 0
140 obj := object{
141 Value: 0,
142 SubObject: subObject{
143 Value: &val,
144 },
145 }
146
147 if _, err = q.PushObjectAsJSON(obj); err != nil {
148 t.Error(err)
149 }
150
151 item, err := q.Pop()
152 if err != nil {
153 t.Error(err)
154 }
155
156 var itemObj object
157 if err := item.ToObjectFromJSON(&itemObj); err != nil {
158 t.Error(err)
159 }
160
161 if *itemObj.SubObject.Value != 0 {
162 t.Errorf("Expected object subobject value to be '0', got '%v'", *itemObj.SubObject.Value)
163 }
164}
165
166func TestStackPeek(t *testing.T) {
167 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())

Callers

nothing calls this directly

Calls 5

OpenStackFunction · 0.85
PushObjectAsJSONMethod · 0.80
PopMethod · 0.80
DropMethod · 0.45
ToObjectFromJSONMethod · 0.45

Tested by

no test coverage detected