...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package bindings
16
17 import (
18 "context"
19 "net/http"
20 "testing"
21
22 "github.com/gopherjs/gopherjs/js"
23
24 kivik "github.com/go-kivik/kivik/v4"
25 )
26
27 func init() {
28 memPouch := js.Global.Get("PouchDB").Call("defaults", map[string]interface{}{
29 "db": js.Global.Call("require", "memdown"),
30 })
31 js.Global.Set("PouchDB", memPouch)
32 }
33
34
35
36 func TestNoFindPlugin(t *testing.T) {
37 t.Run("FindLoaded", func(t *testing.T) {
38 db := GlobalPouchDB().New("foo", nil)
39 _, err := db.Find(context.Background(), "")
40 if kivik.HTTPStatus(err) == http.StatusNotImplemented {
41 t.Errorf("Got StatusNotImplemented when pouchdb-find should be loaded")
42 }
43 })
44 t.Run("FindNotLoaded", func(t *testing.T) {
45 db := GlobalPouchDB().New("foo", nil)
46 db.Object.Set("find", nil)
47 _, err := db.Find(context.Background(), "")
48 if code := kivik.HTTPStatus(err); code != http.StatusNotImplemented {
49 t.Errorf("Expected %d error, got %d/%s\n", http.StatusNotImplemented, code, err)
50 }
51 })
52 }
53
View as plain text