mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 19:37:51 +00:00
Add unit test
This commit is contained in:
parent
b787fccf3a
commit
21969b1637
2 changed files with 36 additions and 1 deletions
11
api.go
11
api.go
|
|
@ -127,6 +127,17 @@ func NewAPI(opts ...apiOption) (*API, error) {
|
|||
return api, nil
|
||||
}
|
||||
|
||||
// Setter for API options.
|
||||
func (api *API) SetAPIOpetions(opts ...apiOption) error {
|
||||
for _, opt := range opts {
|
||||
err := opt(api)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "applying option")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validAPIMethods specifies the api methods that are valid for each
|
||||
// cluster state.
|
||||
var validAPIMethods = map[disco.ClusterState]map[apiMethod]struct{}{
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/molecula/featurebase/v2"
|
||||
pilosa "github.com/molecula/featurebase/v2"
|
||||
"github.com/molecula/featurebase/v2/boltdb"
|
||||
"github.com/molecula/featurebase/v2/encoding/proto"
|
||||
"github.com/molecula/featurebase/v2/http"
|
||||
|
|
@ -344,6 +344,30 @@ func TestHandler_Endpoints(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("SchemaDetailsOff", func(t *testing.T) {
|
||||
cmd.API.SetAPIOpetions(pilosa.OptAPISchemaDetailsOn(false))
|
||||
defer cmd.API.SetAPIOpetions(pilosa.OptAPISchemaDetailsOn(true))
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema/details", nil))
|
||||
if w.Code != gohttp.StatusOK {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
}
|
||||
|
||||
var bodySchema pilosa.Schema
|
||||
if err := json.Unmarshal(w.Body.Bytes(),
|
||||
&bodySchema); err != nil {
|
||||
t.Fatalf("unexpected unmarshalling error: %v", err)
|
||||
}
|
||||
|
||||
for _, i := range bodySchema.Indexes {
|
||||
for _, f := range i.Fields {
|
||||
if f.Cardinality != nil {
|
||||
t.Fatalf("expected nil cardinality, got: %v", *f.Cardinality)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Import", func(t *testing.T) {
|
||||
indexInfo, err := cmd.API.Schema(context.Background(), false)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue