From 759f4d000a5532ed409fe3b7e4e5a06aa9533778 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Wed, 17 Jul 2024 10:33:03 +0200 Subject: [PATCH] Update tests --- find_test.go | 12 +++++++++--- mockdb/db_test.go | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/find_test.go b/find_test.go index 431097a56..1ebfcee00 100644 --- a/find_test.go +++ b/find_test.go @@ -14,6 +14,7 @@ package kivik import ( "context" + "encoding/json" "errors" "fmt" "net/http" @@ -31,6 +32,7 @@ func TestFind(t *testing.T) { name string db *DB query interface{} + options []Option expected *ResultSet status int err string @@ -63,7 +65,7 @@ func TestFind(t *testing.T) { client: &Client{}, driverDB: &mock.Finder{ FindFunc: func(_ context.Context, query interface{}, _ driver.Options) (driver.Rows, error) { - expectedQuery := int(3) + expectedQuery := json.RawMessage(`{"limit":3,"selector":{"foo":"bar"},"skip":10}`) if d := testy.DiffInterface(expectedQuery, query); d != nil { return nil, fmt.Errorf("Unexpected query:\n%s", d) } @@ -71,7 +73,11 @@ func TestFind(t *testing.T) { }, }, }, - query: int(3), + query: map[string]interface{}{"selector": map[string]interface{}{"foo": "bar"}}, + options: []Option{ + Param("limit", 3), + Param("skip", 10), + }, expected: &ResultSet{ iter: &iter{ feed: &rowsIterator{ @@ -105,7 +111,7 @@ func TestFind(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - rs := test.db.Find(context.Background(), test.query) + rs := test.db.Find(context.Background(), test.query, test.options...) err := rs.Err() if d := internal.StatusErrorDiff(test.err, test.status, err); d != "" { t.Error(d) diff --git a/mockdb/db_test.go b/mockdb/db_test.go index 2388bab9f..805682dee 100644 --- a/mockdb/db_test.go +++ b/mockdb/db_test.go @@ -487,7 +487,7 @@ func TestFind(t *testing.T) { }, test: func(t *testing.T, c *kivik.Client) { db := c.DB("foo") - rows := db.Find(context.TODO(), 321) + rows := db.Find(context.TODO(), map[string]interface{}{"selector": map[string]interface{}{"foo": "123"}}) if err := rows.Err(); !testy.ErrorMatchesRE("has query: 123", err) { t.Errorf("Unexpected error: %s", err) } @@ -505,7 +505,7 @@ func TestFind(t *testing.T) { }, test: func(t *testing.T, c *kivik.Client) { db := c.DB("foo") - rows := db.Find(context.TODO(), 7) + rows := db.Find(context.TODO(), map[string]interface{}{}) if err := rows.Err(); !testy.ErrorMatches("", err) { t.Errorf("Unexpected error: %s", err) } @@ -543,7 +543,7 @@ func TestFind(t *testing.T) { }, test: func(t *testing.T, c *kivik.Client) { db := c.DB("foo") - rows := db.Find(newCanceledContext(), 0) + rows := db.Find(newCanceledContext(), map[string]interface{}{}) if err := rows.Err(); !testy.ErrorMatches("context canceled", err) { t.Errorf("Unexpected error: %s", err) } @@ -561,7 +561,7 @@ func TestFind(t *testing.T) { test: func(t *testing.T, c *kivik.Client) { foo := c.DB("foo") _ = c.DB("bar") - rows := foo.Find(context.TODO(), 1) + rows := foo.Find(context.TODO(), map[string]interface{}{}) if err := rows.Err(); !testy.ErrorMatchesRE(`Expected: call to DB\(bar`, err) { t.Errorf("Unexpected error: %s", err) }