Delete a text measurement type

This commit is contained in:
Matthew Dillon 2014-11-28 17:26:01 -09:00
parent 49621ca27b
commit 431ba7ed91
9 changed files with 142 additions and 1 deletions

View file

@ -35,8 +35,11 @@ type TextMeasurementTypesService interface {
// Create a text measurement type
Create(text_measurement_type *TextMeasurementType) (bool, error)
// Updated a text measurement type
// Update a text measurement type
Update(id int64, TextMeasurementType *TextMeasurementType) (updated bool, err error)
// Delete a text measurement type
Delete(id int64) (deleted bool, err error)
}
var (
@ -133,11 +136,34 @@ func (s *textMeasurementTypesService) Update(id int64, text_measurement_type *Te
return resp.StatusCode == http.StatusOK, nil
}
func (s *textMeasurementTypesService) Delete(id int64) (bool, error) {
strId := strconv.FormatInt(id, 10)
url, err := s.client.url(router.DeleteTextMeasurementType, map[string]string{"Id": strId}, nil)
if err != nil {
return false, err
}
req, err := s.client.NewRequest("DELETE", url.String(), nil)
if err != nil {
return false, err
}
var text_measurement_type *TextMeasurementType
resp, err := s.client.Do(req, &text_measurement_type)
if err != nil {
return false, err
}
return resp.StatusCode == http.StatusOK, nil
}
type MockTextMeasurementTypesService struct {
Get_ func(id int64) (*TextMeasurementType, error)
List_ func(opt *TextMeasurementTypeListOptions) ([]*TextMeasurementType, error)
Create_ func(text_measurement_type *TextMeasurementType) (bool, error)
Update_ func(id int64, text_measurement_type *TextMeasurementType) (bool, error)
Delete_ func(id int64) (bool, error)
}
var _ TextMeasurementTypesService = &MockTextMeasurementTypesService{}
@ -169,3 +195,10 @@ func (s *MockTextMeasurementTypesService) Update(id int64, text_measurement_type
}
return s.Update_(id, text_measurement_type)
}
func (s *MockTextMeasurementTypesService) Delete(id int64) (bool, error) {
if s.Delete_ == nil {
return false, nil
}
return s.Delete_(id)
}

View file

@ -143,3 +143,32 @@ func TestTextMeasurementTypeService_Update(t *testing.T) {
t.Fatal("!called")
}
}
func TestTextMeasurementTypeService_Delete(t *testing.T) {
setup()
defer teardown()
want := newTextMeasurementType()
var called bool
mux.HandleFunc(urlPath(t, router.DeleteTextMeasurementType, map[string]string{"Id": "1"}), func(w http.ResponseWriter, r *http.Request) {
called = true
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusOK)
writeJSON(w, want)
})
deleted, err := client.TextMeasurementTypes.Delete(want.Id)
if err != nil {
t.Errorf("TextMeasurementTypes.Delete returned error: %v", err)
}
if !deleted {
t.Error("!deleted")
}
if !called {
t.Fatal("!called")
}
}