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

Function TestQueueUpdateString

queue_test.go:319–362  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

317}
318
319func TestQueueUpdateString(t *testing.T) {
320 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
321 q, err := OpenQueue(file)
322 if err != nil {
323 t.Error(err)
324 }
325 defer q.Drop()
326
327 for i := 1; i <= 10; i++ {
328 if _, err = q.EnqueueString(fmt.Sprintf("value for item %d", i)); err != nil {
329 t.Error(err)
330 }
331 }
332
333 item, err := q.PeekByID(3)
334 if err != nil {
335 t.Error(err)
336 }
337
338 oldCompStr := "value for item 3"
339 newCompStr := "new value for item 3"
340
341 if item.ToString() != oldCompStr {
342 t.Errorf("Expected string to be '%s', got '%s'", oldCompStr, item.ToString())
343 }
344
345 updatedItem, err := q.UpdateString(item.ID, newCompStr)
346 if err != nil {
347 t.Error(err)
348 }
349
350 if updatedItem.ToString() != newCompStr {
351 t.Errorf("Expected current item value to be '%s', got '%s'", newCompStr, item.ToString())
352 }
353
354 newItem, err := q.PeekByID(3)
355 if err != nil {
356 t.Error(err)
357 }
358
359 if newItem.ToString() != newCompStr {
360 t.Errorf("Expected new item value to be '%s', got '%s'", newCompStr, item.ToString())
361 }
362}
363
364func TestQueueUpdateObject(t *testing.T) {
365 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())

Callers

nothing calls this directly

Calls 6

OpenQueueFunction · 0.85
DropMethod · 0.45
EnqueueStringMethod · 0.45
PeekByIDMethod · 0.45
ToStringMethod · 0.45
UpdateStringMethod · 0.45

Tested by

no test coverage detected