This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
/
requests_test.go
113 lines (100 loc) · 3.4 KB
/
requests_test.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
111
112
113
package domains
import (
"fmt"
"net/http"
"reflect"
"testing"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
func TestListSinglePage(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
testhelper.Mux.HandleFunc("/domains", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `
{
"domains": [
{
"description": "Used for swift functional testing",
"enabled": true,
"id": "5a75994a383c449184053ff7270c4e91",
"links": {
"self": "http://example.com/identity/v3/domains/5a75994a383c449184053ff7270c4e91"
},
"name": "swift_test"
},
{
"description": "Owns users and tenants (i.e. projects) available on Identity API v2.",
"enabled": true,
"id": "default",
"links": {
"self": "http://example.com/identity/v3/domains/default"
},
"name": "Default"
}
],
"links": {
"next": null,
"previous": null,
"self": "http://example.com/identity/v3/domains"
}
}
`)
})
count := 0
err := List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractDomains(page)
if err != nil {
return false, err
}
expected := []Domain{
Domain{
Description: "Used for swift functional testing",
ID: "5a75994a383c449184053ff7270c4e91",
Name: "swift_test",
Enabled: true,
Links: Link{Self: "http://example.com/identity/v3/domains/5a75994a383c449184053ff7270c4e91"},
},
Domain{
Description: "Owns users and tenants (i.e. projects) available on Identity API v2.",
ID: "default",
Name: "Default",
Enabled: true,
Links: Link{Self: "http://example.com/identity/v3/domains/default"},
},
}
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Expected %#v, got %#v", expected, actual)
}
return true, nil
})
if err != nil {
t.Errorf("Unexpected error while paging: %v", err)
}
if count != 1 {
t.Errorf("Expected 1 page, got %d", count)
}
}
func TestPairDomainGroupAndRole(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
testhelper.Mux.HandleFunc("/domains/5a75994a383c449184053ff7270c4e91/groups/5a75994a383c449184053ff7270c4e92/roles/5a75994a383c449184053ff7270c4e93", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "PUT")
testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
pair := PairOpts{
ID: "5a75994a383c449184053ff7270c4e91",
GroupID: "5a75994a383c449184053ff7270c4e92",
RoleID: "5a75994a383c449184053ff7270c4e93",
}
err := Pair(client.ServiceClient(), pair)
if err != nil {
t.Fatalf("Unexpected error from Pair: %v", err)
}
}