forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_data.go
87 lines (76 loc) · 2.42 KB
/
fake_data.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
package helpers
import (
"embed"
"fmt"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
"net/http"
)
//go:embed fixtures
var content embed.FS
// AddFiftyOneOrgs adds a mock handler to the given server which returns
// 51 orgs on GET requests to /v3/organizations?order_by=name. It also
// paginates, so page 2 can be requested with /v3/organizations?page=2&per_page=50.
func AddFiftyOneOrgs(server *ghttp.Server) {
AddHandler(server,
http.MethodGet,
"/v3/organizations?order_by=name",
http.StatusOK,
[]byte(fmt.Sprintf(string(fixtureData("fifty-orgs-page-1.json")), server.URL())),
)
AddHandler(server,
http.MethodGet,
"/v3/organizations?page=2&per_page=50",
http.StatusOK,
fixtureData("fifty-orgs-page-2.json"),
)
}
// AddFiftyOneSpaces adds mock handlers to the given http server which includes
// an organization which will contain 51 spaces
func AddFiftyOneSpaces(server *ghttp.Server) {
AddHandler(server,
http.MethodGet,
"/v3/organizations?order_by=name",
http.StatusOK,
[]byte(fmt.Sprintf(string(fixtureData("fifty-spaces-org.json")), server.URL())),
)
AddHandler(server,
http.MethodGet,
"/v3/spaces?organization_guids=4305313e-d34e-4015-9a57-5550235cd6b0",
http.StatusOK,
[]byte(fmt.Sprintf(string(fixtureData("fifty-spaces-page-1.json")), server.URL())),
)
AddHandler(server,
http.MethodGet,
"/v3/spaces?order_by=name&organization_guids=4305313e-d34e-4015-9a57-5550235cd6b0",
http.StatusOK,
[]byte(fmt.Sprintf(string(fixtureData("fifty-spaces-page-1.json")), server.URL())),
)
AddHandler(server,
http.MethodGet,
"/v3/spaces?organization_guids=4305313e-d34e-4015-9a57-5550235cd6b0&page=2&per_page=50",
http.StatusOK,
[]byte(fmt.Sprintf(string(fixtureData("fifty-spaces-page-2.json")), server.URL())),
)
AddHandler(server,
http.MethodGet,
"/v3/spaces?order_by=name&organization_guids=4305313e-d34e-4015-9a57-5550235cd6b0&page=2&per_page=50",
http.StatusOK,
[]byte(fmt.Sprintf(string(fixtureData("fifty-spaces-page-2.json")), server.URL())),
)
}
// AddEmptyPaginatedResponse adds a mock handler to the given server which returns
// a response with no resources.
func AddEmptyPaginatedResponse(server *ghttp.Server, path string) {
AddHandler(server,
http.MethodGet,
path,
http.StatusOK,
fixtureData("empty-paginated-response.json"),
)
}
func fixtureData(name string) []byte {
b, err := content.ReadFile("fixtures/" + name)
Expect(err).ToNot(HaveOccurred())
return b
}