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

Function TestPrefixQueueUpdateString

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

Source from the content-addressed store, hash-verified

267}
268
269func TestPrefixQueueUpdateString(t *testing.T) {
270 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
271 pq, err := OpenPrefixQueue(file)
272 if err != nil {
273 t.Error(err)
274 }
275 defer pq.Drop()
276
277 for i := 1; i <= 10; i++ {
278 if _, err = pq.EnqueueString("prefix", fmt.Sprintf("value for item %d", i)); err != nil {
279 t.Error(err)
280 }
281 }
282
283 item, err := pq.PeekByIDString("prefix", 3)
284 if err != nil {
285 t.Error(err)
286 }
287
288 oldCompStr := "value for item 3"
289 newCompStr := "new value for item 3"
290
291 if item.ToString() != oldCompStr {
292 t.Errorf("Expected string to be '%s', got '%s'", oldCompStr, item.ToString())
293 }
294
295 updatedItem, err := pq.UpdateString("prefix", item.ID, newCompStr)
296 if err != nil {
297 t.Error(err)
298 }
299
300 if updatedItem.ToString() != newCompStr {
301 t.Errorf("Expected current item value to be '%s', got '%s'", newCompStr, item.ToString())
302 }
303
304 newItem, err := pq.PeekByIDString("prefix", 3)
305 if err != nil {
306 t.Error(err)
307 }
308
309 if newItem.ToString() != newCompStr {
310 t.Errorf("Expected new item value to be '%s', got '%s'", newCompStr, item.ToString())
311 }
312}
313
314func TestPrefixQueueUpdateObject(t *testing.T) {
315 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())

Callers

nothing calls this directly

Calls 6

OpenPrefixQueueFunction · 0.85
PeekByIDStringMethod · 0.80
DropMethod · 0.45
EnqueueStringMethod · 0.45
ToStringMethod · 0.45
UpdateStringMethod · 0.45

Tested by

no test coverage detected