github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/pkg/couchdb/cursor_test.go (about) 1 package couchdb 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestCursor(t *testing.T) { 10 if testing.Short() { 11 t.Skip("an instance is required for this test: test skipped due to the use of --short flag") 12 } 13 14 t.Run("StartKeyCursor", func(t *testing.T) { 15 req1 := &ViewRequest{ 16 Key: []string{"A", "B"}, 17 } 18 19 c1 := NewKeyCursor(10, []string{"A", "B"}, "last-result-id") 20 21 c1.ApplyTo(req1) 22 assert.Nil(t, req1.Key) 23 assert.Equal(t, []string{"A", "B"}, req1.StartKey) 24 assert.Equal(t, "last-result-id", req1.StartKeyDocID) 25 assert.Equal(t, 11, req1.Limit) 26 27 c2 := NewKeyCursor(3, nil, "") 28 29 res := &ViewResponse{ 30 Rows: []*ViewResponseRow{ 31 {Key: []string{"A", "B"}, ID: "resultA"}, 32 {Key: []string{"A", "B"}, ID: "resultB"}, 33 {Key: []string{"A", "B"}, ID: "resultC"}, 34 {Key: []string{"A", "B"}, ID: "resultD"}, 35 }, 36 } 37 38 c2.UpdateFrom(res) 39 assert.Len(t, res.Rows, 3) 40 assert.Equal(t, []string{"A", "B"}, c2.(*StartKeyCursor).NextKey) 41 assert.Equal(t, "resultD", c2.(*StartKeyCursor).NextDocID) 42 }) 43 }