Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flimzy committed Jul 17, 2024
1 parent 163a7ce commit 759f4d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 9 additions & 3 deletions find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package kivik

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
Expand All @@ -31,6 +32,7 @@ func TestFind(t *testing.T) {
name string
db *DB
query interface{}
options []Option
expected *ResultSet
status int
err string
Expand Down Expand Up @@ -63,15 +65,19 @@ 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)
}
return &mock.Rows{ID: "a"}, nil
},
},
},
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{
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions mockdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 759f4d0

Please sign in to comment.