/
fake_data.go
39 lines (34 loc) · 994 Bytes
/
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
package helpers
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
)
// 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"),
)
}
func fixtureData(name string) []byte {
wd := os.Getenv("GOPATH")
fp := filepath.Join(wd, "src", "code.cloudfoundry.org", "cli", "integration", "helpers", "fixtures", name)
b, err := ioutil.ReadFile(fp)
Expect(err).ToNot(HaveOccurred())
return b
}