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

Commit e8e4ee4

Browse files
James FisherSamuel Ortiz
authored andcommitted
tests for Create
1 parent d1ede46 commit e8e4ee4

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

openstack/imageservice/v2/fixtures.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package v2
2+
3+
// TODO
4+
5+
import (
6+
"fmt"
7+
"net/http"
8+
"testing"
9+
10+
th "github.com/rackspace/gophercloud/testhelper"
11+
fakeclient "github.com/rackspace/gophercloud/testhelper/client"
12+
)
13+
14+
func HandleImageCreationSuccessfully(t *testing.T) {
15+
th.Mux.HandleFunc("/images", func(w http.ResponseWriter, r *http.Request) {
16+
// TODO
17+
th.TestMethod(t, r, "POST")
18+
th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID)
19+
th.TestJSONRequest(t, r, `{
20+
"id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
21+
"name": "Ubuntu 12.10",
22+
"tags": [
23+
"ubuntu",
24+
"quantal"
25+
]
26+
}`)
27+
28+
w.WriteHeader(http.StatusOK)
29+
w.Header().Add("Content-Type", "application/json")
30+
fmt.Fprintf(w, `{
31+
"status": "queued",
32+
"name": "Ubuntu 12.10",
33+
"tags": ["ubuntu","quantal"],
34+
"container_format": "bare",
35+
"created_at": "2014-11-11T20:47:55Z",
36+
"disk_format": "qcow2",
37+
"updated_at": "2014-11-11T20:47:55Z",
38+
"visibility": "private",
39+
"self": "/v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
40+
"min_disk": 0,
41+
"protected": false,
42+
"id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
43+
"file": "/v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd/file",
44+
"owner": "b4eedccc6fb74fa8a7ad6b08382b852b",
45+
"min_ram": 0,
46+
"schema": "/v2/schemas/image",
47+
"size": "None",
48+
"checksum": "None",
49+
"virtual_size": "None"
50+
}`)
51+
})
52+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
package v2
22

33
// TODO
4+
// compare with openstack/compute/v2/servers/requests_test.go
5+
6+
import (
7+
"testing"
8+
9+
th "github.com/rackspace/gophercloud/testhelper"
10+
fakeclient "github.com/rackspace/gophercloud/testhelper/client"
11+
)
12+
13+
func TestCreateImage(t *testing.T) {
14+
th.SetupHTTP()
15+
defer th.TeardownHTTP()
16+
17+
HandleImageCreationSuccessfully(t)
18+
19+
actualImage, err := Create(fakeclient.ServiceClient(), CreateOpts{
20+
Name: "Ubuntu 12.10",
21+
Id: "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
22+
Tags: []string{"ubuntu", "quantal"},
23+
}).Extract()
24+
25+
th.AssertNoErr(t, err)
26+
27+
expectedImage := Image{
28+
Name: "Ubuntu 12.10",
29+
Id: "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
30+
Tags: []string{"ubuntu", "quantal"},
31+
}
32+
33+
th.AssertDeepEquals(t, &expectedImage, actualImage)
34+
}

0 commit comments

Comments
 (0)