blob: 640d68213a3e324c5a93e411637739fceb4ed3c3 [file] [log] [blame]
Ash Wilsond5506542014-10-21 09:02:16 -04001package images
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 "github.com/rackspace/gophercloud/pagination"
9 th "github.com/rackspace/gophercloud/testhelper"
10 "github.com/rackspace/gophercloud/testhelper/client"
11)
12
13func TestListImageDetails(t *testing.T) {
14 th.SetupHTTP()
15 defer th.TeardownHTTP()
16
17 th.Mux.HandleFunc("/images/detail", func(w http.ResponseWriter, r *http.Request) {
18 th.TestMethod(t, r, "GET")
19 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
20
21 w.Header().Add("Content-Type", "application/json")
22 r.ParseForm()
23 marker := r.Form.Get("marker")
24 switch marker {
25 case "":
26 fmt.Fprintf(w, ListOutput)
27 case "e19a734c-c7e6-443a-830c-242209c4d65d":
28 fmt.Fprintf(w, `{ "images": [] }`)
29 default:
30 t.Fatalf("Unexpected marker: [%s]", marker)
31 }
32 })
33
34 count := 0
35 err := ListDetail(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
36 count++
37 actual, err := ExtractImages(page)
38 th.AssertNoErr(t, err)
39 th.CheckDeepEquals(t, ExpectedImageSlice, actual)
40
41 return true, nil
42 })
43 th.AssertNoErr(t, err)
44 if count < 1 {
45 t.Fatalf("At least one page of image results expected.")
46 }
47}
Ash Wilson9b762e72014-10-21 09:06:37 -040048
49func TestGetImageDetails(t *testing.T) {
50 th.SetupHTTP()
51 defer th.TeardownHTTP()
52
53 th.Mux.HandleFunc("/images/e19a734c-c7e6-443a-830c-242209c4d65d", func(w http.ResponseWriter, r *http.Request) {
54 th.TestMethod(t, r, "GET")
55 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
56
57 w.Header().Add("Content-Type", "application/json")
58 fmt.Fprintf(w, GetOutput)
59 })
60
61 actual, err := Get(client.ServiceClient(), "e19a734c-c7e6-443a-830c-242209c4d65d").Extract()
62 th.AssertNoErr(t, err)
63 th.CheckDeepEquals(t, &UbuntuImage, actual)
64}