Add some error handling

This commit is contained in:
Samir Patel 2021-10-31 23:48:43 -05:00
parent 163492801f
commit faa831928c
3 changed files with 19 additions and 5 deletions

5
api.go
View file

@ -130,7 +130,10 @@ func NewAPI(opts ...apiOption) (*API, error) {
// Setter for API options.
func (api *API) SetAPIOptions(opts ...apiOption) error {
for _, opt := range opts {
opt(api)
err := opt(api)
if err != nil {
return errors.Wrap(err, "setting API option")
}
}
return nil
}

View file

@ -850,7 +850,10 @@ func TestAPI_SchemaDetailsOff(t *testing.T) {
cluster := test.MustRunCluster(t, 2)
defer cluster.Close()
cmd := cluster.GetNode(0)
cmd.API.SetAPIOptions(pilosa.OptAPISchemaDetailsOn(false))
err := cmd.API.SetAPIOptions(pilosa.OptAPISchemaDetailsOn(false))
if err != nil {
t.Fatalf("could not toggle schema details to off: %v", err)
}
schema, err := cmd.API.SchemaDetails(context.Background())
if err != nil {
t.Fatalf("getting schema: %v", err)

View file

@ -345,8 +345,11 @@ func TestHandler_Endpoints(t *testing.T) {
})
t.Run("SchemaDetailsOff", func(t *testing.T) {
cmd.API.SetAPIOptions(pilosa.OptAPISchemaDetailsOn(false))
defer cmd.API.SetAPIOptions(pilosa.OptAPISchemaDetailsOn(true))
err := cmd.API.SetAPIOptions(pilosa.OptAPISchemaDetailsOn(false))
if err != nil {
t.Fatalf("setting schema details option")
}
w := httptest.NewRecorder()
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema/details", nil))
if w.Code != gohttp.StatusOK {
@ -357,8 +360,8 @@ func TestHandler_Endpoints(t *testing.T) {
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 {
@ -366,6 +369,11 @@ func TestHandler_Endpoints(t *testing.T) {
}
}
}
err = cmd.API.SetAPIOptions(pilosa.OptAPISchemaDetailsOn(true))
if err != nil {
t.Fatalf("could not toggle schema details to on: %v", err)
}
})
t.Run("Import", func(t *testing.T) {