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

Function TestStackUpdateString

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

Source from the content-addressed store, hash-verified

317}
318
319func TestStackUpdateString(t *testing.T) {
320 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
321 s, err := OpenStack(file)
322 if err != nil {
323 t.Error(err)
324 }
325 defer s.Drop()
326
327 for i := 1; i <= 10; i++ {
328 if _, err = s.PushString(fmt.Sprintf("value for item %d", i)); err != nil {
329 t.Error(err)
330 }
331 }
332
333 item, err := s.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 := s.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 := s.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 TestStackUpdateObject(t *testing.T) {
365 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())

Callers

nothing calls this directly

Calls 6

OpenStackFunction · 0.85
PushStringMethod · 0.80
DropMethod · 0.45
PeekByIDMethod · 0.45
ToStringMethod · 0.45
UpdateStringMethod · 0.45

Tested by

no test coverage detected