Skip to content

Commit

Permalink
[api] placement delete: return 404 if not found (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
schallert authored and Richard Artoul committed Jun 6, 2019
1 parent e249c30 commit bc64155
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/query/api/v1/handler/placement/delete_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path"
"time"

"github.com/m3db/m3/src/cluster/kv"
"github.com/m3db/m3/src/query/api/v1/handler"
"github.com/m3db/m3/src/query/util/logging"
xhttp "github.com/m3db/m3/src/x/net/http"
Expand Down Expand Up @@ -79,6 +80,11 @@ func (h *DeleteAllHandler) ServeHTTP(serviceName string, w http.ResponseWriter,
}

if err := service.Delete(); err != nil {
if err == kv.ErrNotFound {
logger.Info("cannot delete absent placement", zap.String("service", serviceName))
xhttp.Error(w, err, http.StatusNotFound)
return
}
logger.Error("unable to delete placement", zap.Error(err))
xhttp.Error(w, err, http.StatusInternalServerError)
return
Expand Down
11 changes: 11 additions & 0 deletions src/query/api/v1/handler/placement/delete_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"testing"

"github.com/m3db/m3/src/cmd/services/m3query/config"
"github.com/m3db/m3/src/cluster/kv"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -64,5 +65,15 @@ func TestPlacementDeleteAllHandler(t *testing.T) {

resp = w.Result()
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)

// Test delete not found error
w = httptest.NewRecorder()
req = httptest.NewRequest(DeleteAllHTTPMethod, M3DBDeleteAllURL, nil)
require.NotNil(t, req)
mockPlacementService.EXPECT().Delete().Return(kv.ErrNotFound)
handler.ServeHTTP(serviceName, w, req)

resp = w.Result()
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
})
}

0 comments on commit bc64155

Please sign in to comment.