github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/lib/cursor_test.go (about) 1 package lib 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 "github.com/qri-io/qri/base/params" 9 ) 10 11 func TestCursorToParams(t *testing.T) { 12 lp := params.List{ 13 OrderBy: params.OrderBy{{Key: "created", Direction: params.OrderDESC}}, 14 Limit: 10, 15 Offset: 20, 16 } 17 c := cursor{nextPage: &lp} 18 params, err := c.ToParams() 19 if err != nil { 20 t.Fatal(err) 21 } 22 actual, err := json.Marshal(params) 23 if err != nil { 24 t.Fatal(err) 25 } 26 expect := `{"limit":"10","offset":"20","orderby":"-created"}` 27 if diff := cmp.Diff(expect, string(actual)); diff != "" { 28 t.Errorf("output mismatch (-want +got):\n%s", diff) 29 } 30 }