123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- package testing
- import (
- "fmt"
- "net/http"
- "testing"
- th "devel.mephi.ru/iacherepanov/openstack-gophercloud/testhelper"
- fake "devel.mephi.ru/iacherepanov/openstack-gophercloud/testhelper/client"
- )
- func MockListResponse(t *testing.T) {
- th.Mux.HandleFunc("/volumes/detail", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- r.ParseForm()
- marker := r.Form.Get("marker")
- switch marker {
- case "":
- fmt.Fprintf(w, `
- {
- "volumes": [
- {
- "volume_type": "lvmdriver-1",
- "created_at": "2015-09-17T03:35:03.000000",
- "bootable": "false",
- "name": "vol-001",
- "os-vol-mig-status-attr:name_id": null,
- "consistencygroup_id": null,
- "source_volid": null,
- "os-volume-replication:driver_data": null,
- "multiattach": false,
- "snapshot_id": null,
- "replication_status": "disabled",
- "os-volume-replication:extended_status": null,
- "encrypted": false,
- "os-vol-host-attr:host": null,
- "availability_zone": "nova",
- "attachments": [{
- "server_id": "83ec2e3b-4321-422b-8706-a84185f52a0a",
- "attachment_id": "05551600-a936-4d4a-ba42-79a037c1-c91a",
- "attached_at": "2016-08-06T14:48:20.000000",
- "host_name": "foobar",
- "volume_id": "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75",
- "device": "/dev/vdc",
- "id": "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75"
- }],
- "id": "289da7f8-6440-407c-9fb4-7db01ec49164",
- "size": 75,
- "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
- "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
- "os-vol-mig-status-attr:migstat": null,
- "metadata": {"foo": "bar"},
- "status": "available",
- "description": null
- },
- {
- "volume_type": "lvmdriver-1",
- "created_at": "2015-09-17T03:32:29.000000",
- "bootable": "false",
- "name": "vol-002",
- "os-vol-mig-status-attr:name_id": null,
- "consistencygroup_id": null,
- "source_volid": null,
- "os-volume-replication:driver_data": null,
- "multiattach": false,
- "snapshot_id": null,
- "replication_status": "disabled",
- "os-volume-replication:extended_status": null,
- "encrypted": false,
- "os-vol-host-attr:host": null,
- "availability_zone": "nova",
- "attachments": [],
- "id": "96c3bda7-c82a-4f50-be73-ca7621794835",
- "size": 75,
- "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
- "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
- "os-vol-mig-status-attr:migstat": null,
- "metadata": {},
- "status": "available",
- "description": null
- }
- ],
- "volumes_links": [
- {
- "href": "%s/volumes/detail?marker=1",
- "rel": "next"
- }]
- }
- `, th.Server.URL)
- case "1":
- fmt.Fprintf(w, `{"volumes": []}`)
- default:
- t.Fatalf("Unexpected marker: [%s]", marker)
- }
- })
- }
- func MockGetResponse(t *testing.T) {
- th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, `
- {
- "volume": {
- "volume_type": "lvmdriver-1",
- "created_at": "2015-09-17T03:32:29.000000",
- "bootable": "false",
- "name": "vol-001",
- "os-vol-mig-status-attr:name_id": null,
- "consistencygroup_id": null,
- "source_volid": null,
- "os-volume-replication:driver_data": null,
- "multiattach": false,
- "snapshot_id": null,
- "replication_status": "disabled",
- "os-volume-replication:extended_status": null,
- "encrypted": false,
- "os-vol-host-attr:host": null,
- "availability_zone": "nova",
- "attachments": [{
- "server_id": "83ec2e3b-4321-422b-8706-a84185f52a0a",
- "attachment_id": "05551600-a936-4d4a-ba42-79a037c1-c91a",
- "attached_at": "2016-08-06T14:48:20.000000",
- "host_name": "foobar",
- "volume_id": "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75",
- "device": "/dev/vdc",
- "id": "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75"
- }],
- "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
- "size": 75,
- "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
- "os-vol-tenant-attr:tenant_id": "304dc00909ac4d0da6c62d816bcb3459",
- "os-vol-mig-status-attr:migstat": null,
- "metadata": {},
- "status": "available",
- "description": null
- }
- }
- `)
- })
- }
- func MockCreateResponse(t *testing.T) {
- th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "POST")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- th.TestHeader(t, r, "Content-Type", "application/json")
- th.TestHeader(t, r, "Accept", "application/json")
- th.TestJSONRequest(t, r, `
- {
- "volume": {
- "name": "vol-001",
- "size": 75
- }
- }
- `)
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusAccepted)
- fmt.Fprintf(w, `
- {
- "volume": {
- "size": 75,
- "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
- "metadata": {},
- "created_at": "2015-09-17T03:32:29.044216",
- "encrypted": false,
- "bootable": "false",
- "availability_zone": "nova",
- "attachments": [],
- "user_id": "ff1ce52c03ab433aaba9108c2e3ef541",
- "status": "creating",
- "description": null,
- "volume_type": "lvmdriver-1",
- "name": "vol-001",
- "replication_status": "disabled",
- "consistencygroup_id": null,
- "source_volid": null,
- "snapshot_id": null,
- "multiattach": false
- }
- }
- `)
- })
- }
- func MockDeleteResponse(t *testing.T) {
- th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "DELETE")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- w.WriteHeader(http.StatusAccepted)
- })
- }
- func MockUpdateResponse(t *testing.T) {
- th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "PUT")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, `
- {
- "volume": {
- "name": "vol-002"
- }
- }
- `)
- })
- }
|