...

Source file src/github.com/go-kivik/kivik/v4/pouchdb/bindings/nofind_test.go

Documentation: github.com/go-kivik/kivik/v4/pouchdb/bindings

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    12  
    13  //go:build js
    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  // TestNoFind tests that Find() properly returns NotImplemented when the
    35  // pouchdb-find plugin is not loaded.
    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) // Fake it
    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