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