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" |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 5 | "github.com/gophercloud/gophercloud" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" |
| 7 | th "github.com/gophercloud/gophercloud/testhelper" |
| 8 | "github.com/gophercloud/gophercloud/testhelper/client" |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 9 | "net/http" |
| 10 | "testing" |
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, |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 48 | ServerGroups: 2, |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 49 | ServerGroupMembers: 3, |
| 50 | } |
| 51 | |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 52 | //The expected update Body. Is also returned by PUT request |
| 53 | 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}}` |
| 54 | |
| 55 | //The expected partialupdate Body. Is also returned by PUT request |
| 56 | const PartialUpdateBody = `{"quota_set":{"cores":200, "force":true}}` |
| 57 | |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 58 | //Result of Quota-update |
| 59 | var UpdatedQuotaSet = quotasets.UpdateOpts{ |
| 60 | FixedIps: gophercloud.IntToPointer(0), |
| 61 | FloatingIps: gophercloud.IntToPointer(0), |
| 62 | InjectedFileContentBytes: gophercloud.IntToPointer(10240), |
| 63 | InjectedFilePathBytes: gophercloud.IntToPointer(255), |
| 64 | InjectedFiles: gophercloud.IntToPointer(5), |
| 65 | KeyPairs: gophercloud.IntToPointer(10), |
| 66 | MetadataItems: gophercloud.IntToPointer(128), |
| 67 | Ram: gophercloud.IntToPointer(200000), |
| 68 | SecurityGroupRules: gophercloud.IntToPointer(20), |
| 69 | SecurityGroups: gophercloud.IntToPointer(10), |
| 70 | Cores: gophercloud.IntToPointer(200), |
| 71 | Instances: gophercloud.IntToPointer(25), |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 72 | ServerGroups: gophercloud.IntToPointer(2), |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 73 | ServerGroupMembers: gophercloud.IntToPointer(3), |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // HandleGetSuccessfully configures the test server to respond to a Get request for sample tenant |
| 77 | func HandleGetSuccessfully(t *testing.T) { |
| 78 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 79 | th.TestMethod(t, r, "GET") |
| 80 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 81 | |
| 82 | w.Header().Add("Content-Type", "application/json") |
| 83 | fmt.Fprintf(w, GetOutput) |
| 84 | }) |
| 85 | } |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 86 | |
| 87 | // HandlePutSuccessfully configures the test server to respond to a Put request for sample tenant |
| 88 | func HandlePutSuccessfully(t *testing.T) { |
| 89 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 90 | th.TestMethod(t, r, "PUT") |
| 91 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 92 | th.TestJSONRequest(t, r, UpdateOutput) |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 93 | w.Header().Add("Content-Type", "application/json") |
| 94 | fmt.Fprintf(w, UpdateOutput) |
| 95 | }) |
| 96 | } |
| 97 | |
| 98 | // HandlePartialPutSuccessfully configures the test server to respond to a Put request for sample tenant that only containes specific values |
| 99 | func HandlePartialPutSuccessfully(t *testing.T) { |
| 100 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 101 | th.TestMethod(t, r, "PUT") |
| 102 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 103 | th.TestJSONRequest(t, r, PartialUpdateBody) |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 104 | w.Header().Add("Content-Type", "application/json") |
| 105 | fmt.Fprintf(w, UpdateOutput) |
| 106 | }) |
| 107 | } |
| 108 | |
| 109 | // HandleDeleteSuccessfully configures the test server to respond to a Delete request for sample tenant |
| 110 | func HandleDeleteSuccessfully(t *testing.T) { |
| 111 | th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) { |
| 112 | th.TestMethod(t, r, "DELETE") |
| 113 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 114 | th.TestBody(t, r, "") |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 115 | w.Header().Add("Content-Type", "application/json") |
| 116 | w.WriteHeader(202) |
| 117 | }) |
jrperritt | 5cb543c | 2017-02-20 14:03:36 -0600 | [diff] [blame^] | 118 | } |