-
Notifications
You must be signed in to change notification settings - Fork 7
/
fixtures.go
89 lines (83 loc) · 2.9 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
package testing
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/rts/v1/stackresources"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
fake "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client"
)
// ListExpected represents the expected object from a List request.
var ListExpected = []stackresources.Resource{
{
Name: "hello_world",
Links: []golangsdk.Link{
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
Rel: "self",
},
{
Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
Rel: "stack",
},
},
LogicalID: "hello_world",
StatusReason: "state changed",
UpdatedTime: time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC),
CreationTime: time.Date(2015, 2, 5, 21, 33, 10, 0, time.UTC),
RequiredBy: []string{},
Status: "CREATE_IN_PROGRESS",
PhysicalID: "49181cd6-169a-4130-9455-31185bbfc5bf",
Type: "OS::Nova::Server",
},
}
// ListOutput represents the response body from a List request.
const ListOutput = `{
"resources": [
{
"resource_name": "hello_world",
"links": [
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world",
"rel": "self"
},
{
"href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b",
"rel": "stack"
}
],
"logical_resource_id": "hello_world",
"resource_status_reason": "state changed",
"updated_time": "2015-02-05T21:33:11",
"required_by": [],
"resource_status": "CREATE_IN_PROGRESS",
"physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf",
"creation_time": "2015-02-05T21:33:10",
"resource_type": "OS::Nova::Server",
"attributes": {"SXSW": "atx"},
"description": "Some resource"
}
]
}`
// HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources`
// on the test handler mux that responds with a `List` response.
func HandleListSuccessfully(t *testing.T, output string) {
th.Mux.HandleFunc("/stacks/hello_world/resources", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
_ = r.ParseForm()
marker := r.Form.Get("marker")
switch marker {
case "":
_, _ = fmt.Fprint(w, output)
case "49181cd6-169a-4130-9455-31185bbfc5bf":
_, _ = fmt.Fprint(w, `{"resources":[]}`)
default:
t.Fatalf("Unexpected marker: [%s]", marker)
}
})
}