github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vbs/v2/shares/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 fake "github.com/huaweicloud/golangsdk/openstack/vbs/v2/common" 9 "github.com/huaweicloud/golangsdk/openstack/vbs/v2/shares" 10 th "github.com/huaweicloud/golangsdk/testhelper" 11 ) 12 13 // listResponse represents the response body from a List request. 14 var listResponse = `{ 15 "shared": [ 16 { 17 "backup_id": "87566ed6-72cb-4053-aa6e-6f6216b3d507", 18 "to_project_id": "91d687759aed45d28b5f6084bc2fa8ad", 19 "from_project_id": "17fbda95add24720a4038ba4b1c705ed", 20 "backup": { 21 "status": "available", 22 "object_count": 0, 23 "container": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3", 24 "name": "c2c-test-buckup", 25 "availability_zone": "eu-de-01", 26 "snapshot_id": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3", 27 "volume_id": "5024a06e-6990-4f12-9dcc-8fe26b01a710", 28 "id": "87566ed6-72cb-4053-aa6e-6f6216b3d507", 29 "size": 10 30 }, 31 "id": "ac0fb374-a288-4399-ac63-cc080a13a2ee" 32 } 33 ] 34 }` 35 36 // getResponse represents the response body from a Get request. 37 var getResponse = `{ 38 "shared": { 39 "backup_id": "87566ed6-72cb-4053-aa6e-6f6216b3d507", 40 "to_project_id": "91d687759aed45d28b5f6084bc2fa8ad", 41 "from_project_id": "17fbda95add24720a4038ba4b1c705ed", 42 "backup": { 43 "status": "available", 44 "object_count": 0, 45 "container": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3", 46 "name": "c2c-test-buckup", 47 "availability_zone": "eu-de-01", 48 "snapshot_id": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3", 49 "volume_id": "5024a06e-6990-4f12-9dcc-8fe26b01a710", 50 "id": "87566ed6-72cb-4053-aa6e-6f6216b3d507", 51 "size": 10 52 }, 53 "id": "ac0fb374-a288-4399-ac63-cc080a13a2ee" 54 } 55 }` 56 57 // HandleGetSuccessfully creates an HTTP handler at `/os-vendor-backup-sharing/ac0fb374-a288-4399-ac63-cc080a13a2ee` 58 // on the test handler mux that responds with a `Get` response. 59 func HandleGetSuccessfully(t *testing.T) { 60 th.Mux.HandleFunc("/os-vendor-backup-sharing/ac0fb374-a288-4399-ac63-cc080a13a2ee", func(w http.ResponseWriter, r *http.Request) { 61 th.TestMethod(t, r, "GET") 62 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 63 w.WriteHeader(http.StatusOK) 64 fmt.Fprintf(w, getResponse) 65 }) 66 } 67 68 // CreateExpected represents the expected object from a Create request. 69 var CreateExpected = []shares.Share{{ 70 BackupID: "87566ed6-72cb-4053-aa6e-6f6216b3d507", 71 ToProjectID: "91d687759aed45d28b5f6084bc2fa8ad", 72 FromProjectID: "17fbda95add24720a4038ba4b1c705ed", 73 ID: "34c38ce7-f35c-44f2-a8d8-8d4ebab0cfbb", 74 }, 75 } 76 77 // CreateOutput represents the response body from a Create request. 78 const CreateOutput = ` 79 { 80 "shared": [ 81 { 82 "backup_id": "87566ed6-72cb-4053-aa6e-6f6216b3d507", 83 "to_project_id": "91d687759aed45d28b5f6084bc2fa8ad", 84 "from_project_id": "17fbda95add24720a4038ba4b1c705ed", 85 "id": "34c38ce7-f35c-44f2-a8d8-8d4ebab0cfbb" 86 } 87 ] 88 }` 89 90 // HandleCreateSuccessfully creates an HTTP handler at `/os-vendor-backup-sharing` on the test handler mux 91 // that responds with a `Create` response. 92 func HandleCreateSuccessfully(t *testing.T, output string) { 93 th.Mux.HandleFunc("/os-vendor-backup-sharing", func(w http.ResponseWriter, r *http.Request) { 94 th.TestMethod(t, r, "POST") 95 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 96 th.TestHeader(t, r, "Accept", "application/json") 97 w.WriteHeader(http.StatusOK) 98 fmt.Fprintf(w, output) 99 }) 100 } 101 102 // HandleDeleteSuccessfully creates an HTTP handler at `/os-vendor-backup-sharing/87566ed6-72cb-4053-aa6e-6f6216b3d507` 103 // on the test handler mux that responds with a `Delete` response. 104 func HandleDeleteSuccessfully(t *testing.T) { 105 th.Mux.HandleFunc("/os-vendor-backup-sharing/87566ed6-72cb-4053-aa6e-6f6216b3d507", func(w http.ResponseWriter, r *http.Request) { 106 th.TestMethod(t, r, "DELETE") 107 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 108 w.WriteHeader(http.StatusOK) 109 }) 110 }