diff --git a/api.go b/api.go index 3d4961626..458164f6e 100644 --- a/api.go +++ b/api.go @@ -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 } diff --git a/api_test.go b/api_test.go index c06c9f8a2..378aee9fd 100644 --- a/api_test.go +++ b/api_test.go @@ -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) diff --git a/server/handler_test.go b/server/handler_test.go index e4c28bece..96b0f12aa 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -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) {