jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 7 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | "github.com/gophercloud/gophercloud/testhelper/client" |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud" |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | // GetOutput is a sample response to a Get call. |
| 14 | const GetOutput = ` |
| 15 | { |
| 16 | "quota_set" : { |
| 17 | "instances" : 25, |
| 18 | "security_groups" : 10, |
| 19 | "security_group_rules" : 20, |
| 20 | "cores" : 200, |
| 21 | "injected_file_content_bytes" : 10240, |
| 22 | "injected_files" : 5, |
| 23 | "metadata_items" : 128, |
| 24 | "ram" : 200000, |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 25 | "key_pairs" : 10, |
| 26 | "injected_file_path_bytes" : 255, |
| 27 | "server_groups" : 2, |
| 28 | "server_group_members" : 3 |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | ` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 32 | const FirstTenantID = "555544443333222211110000ffffeeee" |
| 33 | |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 34 | // FirstQuotaSet is the first result in ListOutput. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 35 | var FirstQuotaSet = quotasets.QuotaSet{ |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 36 | FixedIps: 0, |
| 37 | FloatingIps: 0, |
| 38 | InjectedFileContentBytes: 10240, |
| 39 | InjectedFilePathBytes: 255, |
| 40 | InjectedFiles: 5, |
| 41 | KeyPairs: 10, |
| 42 | MetadataItems: 128, |
| 43 | Ram: 200000, |
| 44 | SecurityGroupRules: 20, |
| 45 | SecurityGroups: 10, |
| 46 | Cores: 200, |
| 47 | Instances: 25, |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 48 | ServerGroups: 2, |
| 49 | ServerGroupMembers: 3, |
| 50 | } |
| 51 | |
| 52 | |
| 53 | //The expected update Body. Is also returned by PUT request |
| 54 | const UpdateOutput = `{"quota_set":{"cores":200,"fixed_ips":0,"floating_ips":0,"injected_file_content_bytes":10240,"injected_file_path_bytes":255,"injected_files":5,"instances":25,"key_pairs":10,"metadata_items":128,"ram":200000,"security_group_rules":20,"security_groups":10,"server_groups":2,"server_group_members":3}}` |
| 55 | |
| 56 | //The expected partialupdate Body. Is also returned by PUT request |
| 57 | const PartialUpdateBody = `{"quota_set":{"cores":200, "force":true}}` |
| 58 | |
| 59 | |
| 60 | //Result of Quota-update |
| 61 | var UpdatedQuotaSet = quotasets.UpdateOpts{ |
| 62 | FixedIps: gophercloud.IntToPointer(0), |
| 63 | FloatingIps: gophercloud.IntToPointer(0), |
| 64 | InjectedFileContentBytes: gophercloud.IntToPointer(10240), |
| 65 | InjectedFilePathBytes: gophercloud.IntToPointer(255), |
| 66 | InjectedFiles: gophercloud.IntToPointer(5), |
| 67 | KeyPairs: gophercloud.IntToPointer(10), |
| 68 | MetadataItems: gophercloud.IntToPointer(128), |
| 69 | Ram: gophercloud.IntToPointer(200000), |
| 70 | SecurityGroupRules: gophercloud.IntToPointer(20), |
| 71 | SecurityGroups: gophercloud.IntToPointer(10), |
| 72 | Cores: gophercloud.IntToPointer(200), |
| 73 | Instances: gophercloud.IntToPointer(25), |
| 74 | ServerGroups: gophercloud.IntToPointer(2), |
| 75 | ServerGroupMembers: gophercloud.IntToPointer(3), |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | // HandleGetSuccessfully configures the test server to respond to a Get request for sample tenant |
| 79 | func HandleGetSuccessfully(t *testing.T) { |
| 80 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 81 | th.TestMethod(t, r, "GET") |
| 82 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 83 | |
| 84 | w.Header().Add("Content-Type", "application/json") |
| 85 | fmt.Fprintf(w, GetOutput) |
| 86 | }) |
| 87 | } |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 88 | |
| 89 | // HandlePutSuccessfully configures the test server to respond to a Put request for sample tenant |
| 90 | func HandlePutSuccessfully(t *testing.T) { |
| 91 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 92 | th.TestMethod(t, r, "PUT") |
| 93 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 94 | th.TestJSONRequest(t,r,UpdateOutput) |
| 95 | w.Header().Add("Content-Type", "application/json") |
| 96 | fmt.Fprintf(w, UpdateOutput) |
| 97 | }) |
| 98 | } |
| 99 | |
| 100 | // HandlePartialPutSuccessfully configures the test server to respond to a Put request for sample tenant that only containes specific values |
| 101 | func HandlePartialPutSuccessfully(t *testing.T) { |
| 102 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 103 | th.TestMethod(t, r, "PUT") |
| 104 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 105 | th.TestJSONRequest(t,r,PartialUpdateBody) |
| 106 | w.Header().Add("Content-Type", "application/json") |
| 107 | fmt.Fprintf(w, UpdateOutput) |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | // HandleDeleteSuccessfully configures the test server to respond to a Delete request for sample tenant |
| 112 | func HandleDeleteSuccessfully(t *testing.T) { |
| 113 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 114 | th.TestMethod(t, r, "DELETE") |
| 115 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 116 | th.TestBody(t,r,"") |
| 117 | w.Header().Add("Content-Type", "application/json") |
| 118 | w.WriteHeader(202) |
| 119 | }) |
| 120 | } |