@@ -105,7 +105,7 @@ func TestStackPop(t *testing.T) {
105105 t .Errorf ("Expected stack length of 10, got %d" , s .Length ())
106106 }
107107
108- deqItem , err := s .Pop ()
108+ popItem , err := s .Pop ()
109109 if err != nil {
110110 t .Error (err )
111111 }
@@ -116,8 +116,8 @@ func TestStackPop(t *testing.T) {
116116
117117 compStr := "value for item 10"
118118
119- if deqItem .ToString () != compStr {
120- t .Errorf ("Expected string to be '%s', got '%s'" , compStr , deqItem .ToString ())
119+ if popItem .ToString () != compStr {
120+ t .Errorf ("Expected string to be '%s', got '%s'" , compStr , popItem .ToString ())
121121 }
122122}
123123
@@ -386,6 +386,46 @@ func TestStackUpdateObject(t *testing.T) {
386386 }
387387}
388388
389+ func TestStackUpdateOutOfBounds (t * testing.T ) {
390+ file := fmt .Sprintf ("test_db_%d" , time .Now ().UnixNano ())
391+ s , err := OpenStack (file )
392+ if err != nil {
393+ t .Error (err )
394+ }
395+ defer s .Drop ()
396+
397+ for i := 1 ; i <= 10 ; i ++ {
398+ item := NewItemString (fmt .Sprintf ("value for item %d" , i ))
399+ if err = s .Push (item ); err != nil {
400+ t .Error (err )
401+ }
402+ }
403+
404+ if s .Length () != 10 {
405+ t .Errorf ("Expected stack length of 10, got %d" , s .Length ())
406+ }
407+
408+ popItem , err := s .Pop ()
409+ if err != nil {
410+ t .Error (err )
411+ }
412+
413+ if s .Length () != 9 {
414+ t .Errorf ("Expected stack length of 9, got %d" , s .Length ())
415+ }
416+
417+ if err = s .Update (popItem , []byte (`new value` )); err != ErrOutOfBounds {
418+ t .Errorf ("Expected to get stack out of bounds error, got %s" , err .Error ())
419+ }
420+
421+ popItem .ID --
422+ popItem .Key = idToKey (popItem .ID )
423+
424+ if err = s .Update (popItem , []byte (`new value` )); err != nil {
425+ t .Error (err )
426+ }
427+ }
428+
389429func TestStackEmpty (t * testing.T ) {
390430 file := fmt .Sprintf ("test_db_%d" , time .Now ().UnixNano ())
391431 s , err := OpenStack (file )
0 commit comments