jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/openstack/common/extensions" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | th "github.com/gophercloud/gophercloud/testhelper" |
| 10 | "github.com/gophercloud/gophercloud/testhelper/client" |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | // ListOutput provides a single page of Extension results. |
| 14 | const ListOutput = ` |
| 15 | { |
| 16 | "extensions": [ |
| 17 | { |
| 18 | "updated": "2013-01-20T00:00:00-00:00", |
| 19 | "name": "Neutron Service Type Management", |
| 20 | "links": [], |
| 21 | "namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0", |
| 22 | "alias": "service-type", |
| 23 | "description": "API for retrieving service providers for Neutron advanced services" |
| 24 | } |
| 25 | ] |
| 26 | }` |
| 27 | |
| 28 | // GetOutput provides a single Extension result. |
| 29 | const GetOutput = ` |
| 30 | { |
| 31 | "extension": { |
| 32 | "updated": "2013-02-03T10:00:00-00:00", |
| 33 | "name": "agent", |
| 34 | "links": [], |
| 35 | "namespace": "http://docs.openstack.org/ext/agent/api/v2.0", |
| 36 | "alias": "agent", |
| 37 | "description": "The agent management extension." |
| 38 | } |
| 39 | } |
| 40 | ` |
| 41 | |
| 42 | // ListedExtension is the Extension that should be parsed from ListOutput. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 43 | var ListedExtension = extensions.Extension{ |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 44 | Updated: "2013-01-20T00:00:00-00:00", |
| 45 | Name: "Neutron Service Type Management", |
| 46 | Links: []interface{}{}, |
| 47 | Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0", |
| 48 | Alias: "service-type", |
| 49 | Description: "API for retrieving service providers for Neutron advanced services", |
| 50 | } |
| 51 | |
| 52 | // ExpectedExtensions is a slice containing the Extension that should be parsed from ListOutput. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 53 | var ExpectedExtensions = []extensions.Extension{ListedExtension} |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 54 | |
| 55 | // SingleExtension is the Extension that should be parsed from GetOutput. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 56 | var SingleExtension = &extensions.Extension{ |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 57 | Updated: "2013-02-03T10:00:00-00:00", |
| 58 | Name: "agent", |
| 59 | Links: []interface{}{}, |
| 60 | Namespace: "http://docs.openstack.org/ext/agent/api/v2.0", |
| 61 | Alias: "agent", |
| 62 | Description: "The agent management extension.", |
| 63 | } |
| 64 | |
| 65 | // HandleListExtensionsSuccessfully creates an HTTP handler at `/extensions` on the test handler |
| 66 | // mux that response with a list containing a single tenant. |
| 67 | func HandleListExtensionsSuccessfully(t *testing.T) { |
| 68 | th.Mux.HandleFunc("/extensions", func(w http.ResponseWriter, r *http.Request) { |
| 69 | th.TestMethod(t, r, "GET") |
| 70 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 71 | |
| 72 | w.Header().Add("Content-Type", "application/json") |
| 73 | |
| 74 | fmt.Fprintf(w, ListOutput) |
| 75 | }) |
| 76 | } |
| 77 | |
| 78 | // HandleGetExtensionSuccessfully creates an HTTP handler at `/extensions/agent` that responds with |
| 79 | // a JSON payload corresponding to SingleExtension. |
| 80 | func HandleGetExtensionSuccessfully(t *testing.T) { |
| 81 | th.Mux.HandleFunc("/extensions/agent", func(w http.ResponseWriter, r *http.Request) { |
| 82 | th.TestMethod(t, r, "GET") |
| 83 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 84 | |
| 85 | w.Header().Add("Content-Type", "application/json") |
| 86 | w.WriteHeader(http.StatusOK) |
| 87 | |
| 88 | fmt.Fprintf(w, GetOutput) |
| 89 | }) |
| 90 | } |