Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 8ba815a

Browse files
James FisherSamuel Ortiz
authored andcommitted
test image deletion
1 parent 9e3d9db commit 8ba815a

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

openstack/imageservice/v2/fixtures.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ func HandleImageGetSuccessfully(t *testing.T) {
8080
}`)
8181
})
8282
}
83+
84+
func HandleImageDeleteSuccessfully(t *testing.T) {
85+
th.Mux.HandleFunc("/images/1bea47ed-f6a9-463b-b423-14b9cca9ad27", func(w http.ResponseWriter, r *http.Request) {
86+
th.TestMethod(t, r, "DELETE")
87+
th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID)
88+
89+
w.WriteHeader(http.StatusNoContent)
90+
})
91+
}

openstack/imageservice/v2/requests.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ func (opts CreateOpts) ToImageCreateMap() (map[string]interface{}, error) {
109109

110110
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
111111
var res DeleteResult
112-
_, res.Err = client.Delete(deleteURL(client, id), nil)
112+
_, res.Err = client.Delete(deleteURL(client, id), &gophercloud.RequestOpts{
113+
OkCodes: []int{204},
114+
})
113115
return res
114116
}
115117

openstack/imageservice/v2/requests_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ func TestGetImage(t *testing.T) {
8888

8989
th.AssertDeepEquals(t, &expectedImage, actualImage)
9090
}
91+
92+
func TestDeleteImage(t *testing.T) {
93+
th.SetupHTTP()
94+
defer th.TeardownHTTP()
95+
96+
HandleImageDeleteSuccessfully(t)
97+
98+
Delete(fakeclient.ServiceClient(), "1bea47ed-f6a9-463b-b423-14b9cca9ad27")
99+
// TODO
100+
}

openstack/imageservice/v2/results.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66

77
"github.com/rackspace/gophercloud"
88
//"github.com/rackspace/gophercloud/pagination"
9-
10-
"github.com/mitchellh/mapstructure"
119
)
1210

1311
// does not include the literal image data; just metadata.
@@ -24,19 +22,19 @@ type Image struct {
2422
ContainerFormat string
2523
DiskFormat string
2624

27-
MinDiskGigabytes int `mapstructure:"min_disk"`
28-
MinRamMegabytes int `mapstructure:"min_ram"`
25+
MinDiskGigabytes int
26+
MinRamMegabytes int
2927

3028
Owner string
3129

3230
Protected bool
3331
Visibility ImageVisibility
3432

35-
Checksum *string `mapstructure:"checksum"`
36-
SizeBytes *int `mapstructure:"size"`
33+
Checksum *string
34+
SizeBytes *int
3735

38-
Metadata map[string]string `mapstructure:"metadata"`
39-
Properties map[string]string `mapstructure:"properties"`
36+
Metadata map[string]string
37+
Properties map[string]string
4038
}
4139

4240
// implements pagination.Page<Image>, pagination.MarkerPage
@@ -300,19 +298,6 @@ func extractImage(res gophercloud.ErrResult) (*Image, error) {
300298
return &image, nil
301299
}
302300

303-
// The response to `POST /images` follows the same schema as `GET /images/:id`.
304-
func extractImageOld(res gophercloud.ErrResult) (*Image, error) {
305-
if res.Err != nil {
306-
return nil, res.Err
307-
}
308-
309-
var image Image
310-
311-
err := mapstructure.Decode(res.Body, &image)
312-
313-
return &image, err
314-
}
315-
316301
func (c CreateResult) Extract() (*Image, error) {
317302
return extractImage(c.ErrResult)
318303
}

0 commit comments

Comments
 (0)