Skip to content

Commit

Permalink
Add Capsule Delete operation
Browse files Browse the repository at this point in the history
Depends-On: gophercloud#944
Depends-On: gophercloud#955

Change-Id: Ib656b520fa334dc07309bf049c99b5d09a9c1028
Signed-off-by: Kevin Zhao <kevin.zhao@arm.com>
  • Loading branch information
Kevin Zhao committed Apr 24, 2018
1 parent 2721628 commit cfce582
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openstack/container/v1/capsules/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
return CapsulePage{pagination.LinkedPageBase{PageResult: r}}
})
}

// Delete implements Capsule delete request.
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, id), nil)
return
}
5 changes: 5 additions & 0 deletions openstack/container/v1/capsules/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ type Capsule struct {
VolumesInfo map[string][]string `json:"volumes_info"`
}

// DeleteResult represents the result of a delete operation.
type DeleteResult struct {
gophercloud.ErrResult
}

type Address struct {
PreserveOnDelete bool `json:"preserve_on_delete"`
Addr string `json:"addr"`
Expand Down
8 changes: 8 additions & 0 deletions openstack/container/v1/capsules/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,11 @@ func HandleCapsuleListSuccessfully(t *testing.T) {
fmt.Fprintf(w, CapsuleListBody)
})
}

func HandleCapsuleDeleteSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/capsules/963a239d-3946-452b-be5a-055eab65a421", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID)
w.WriteHeader(http.StatusNoContent)
})
}
10 changes: 10 additions & 0 deletions openstack/container/v1/capsules/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,13 @@ func TestListCapsule(t *testing.T) {
t.Errorf("Expected 1 page, got %d", count)
}
}

func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

HandleCapsuleDeleteSuccessfully(t)

res := capsules.Delete(fakeclient.ServiceClient(), "963a239d-3946-452b-be5a-055eab65a421")
th.AssertNoErr(t, res.Err)
}
4 changes: 4 additions & 0 deletions openstack/container/v1/capsules/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ func getURL(client *gophercloud.ServiceClient, id string) string {
func listURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL("capsules")
}

func deleteURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("capsules", id)
}

0 comments on commit cfce582

Please sign in to comment.