github.com/elves/elvish@v0.15.0/pkg/cli/histutil/db_store_test.go (about) 1 package histutil 2 3 import ( 4 "testing" 5 6 "github.com/elves/elvish/pkg/store" 7 ) 8 9 func TestDBStore_Cursor(t *testing.T) { 10 db := NewFaultyInMemoryDB("+ 1", "- 2", "+ 3") 11 s, err := NewDBStore(db) 12 if err != nil { 13 panic(err) 14 } 15 16 testCursorIteration(t, s.Cursor("+"), []store.Cmd{ 17 {Text: "+ 1", Seq: 0}, 18 {Text: "+ 3", Seq: 2}, 19 }) 20 21 // Test error conditions. 22 c := s.Cursor("+") 23 24 expect := func(wantCmd store.Cmd, wantErr error) { 25 t.Helper() 26 cmd, err := c.Get() 27 if cmd != wantCmd { 28 t.Errorf("Get -> %v, want %v", cmd, wantCmd) 29 } 30 if err != wantErr { 31 t.Errorf("Get -> error %v, want %v", err, wantErr) 32 } 33 } 34 35 db.SetOneOffError(errMock) 36 c.Prev() 37 expect(store.Cmd{Seq: 3}, errMock) 38 39 c.Prev() 40 expect(store.Cmd{Text: "+ 3", Seq: 2}, nil) 41 42 db.SetOneOffError(errMock) 43 c.Prev() 44 expect(store.Cmd{Text: "+ 3", Seq: 2}, errMock) 45 46 db.SetOneOffError(errMock) 47 c.Next() 48 expect(store.Cmd{Text: "+ 3", Seq: 2}, errMock) 49 } 50 51 // Remaining methods tested with HybridStore.