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

Function TestQueueUpdate

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

Source from the content-addressed store, hash-verified

272}
273
274func TestQueueUpdate(t *testing.T) {
275 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
276 q, err := OpenQueue(file)
277 if err != nil {
278 t.Error(err)
279 }
280 defer q.Drop()
281
282 for i := 1; i <= 10; i++ {
283 if _, err = q.EnqueueString(fmt.Sprintf("value for item %d", i)); err != nil {
284 t.Error(err)
285 }
286 }
287
288 item, err := q.PeekByID(3)
289 if err != nil {
290 t.Error(err)
291 }
292
293 oldCompStr := "value for item 3"
294 newCompStr := "new value for item 3"
295
296 if item.ToString() != oldCompStr {
297 t.Errorf("Expected string to be '%s', got '%s'", oldCompStr, item.ToString())
298 }
299
300 updatedItem, err := q.Update(item.ID, []byte(newCompStr))
301 if err != nil {
302 t.Error(err)
303 }
304
305 if updatedItem.ToString() != newCompStr {
306 t.Errorf("Expected current item value to be '%s', got '%s'", newCompStr, item.ToString())
307 }
308
309 newItem, err := q.PeekByID(3)
310 if err != nil {
311 t.Error(err)
312 }
313
314 if newItem.ToString() != newCompStr {
315 t.Errorf("Expected new item value to be '%s', got '%s'", newCompStr, item.ToString())
316 }
317}
318
319func TestQueueUpdateString(t *testing.T) {
320 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
UpdateMethod · 0.45

Tested by

no test coverage detected