github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/helpers/fake_data.go (about)

     1  package helpers
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"net/http"
     7  	"os"
     8  	"path/filepath"
     9  
    10  	. "github.com/onsi/gomega"
    11  	"github.com/onsi/gomega/ghttp"
    12  )
    13  
    14  // AddFiftyOneOrgs adds a mock handler to the given server which returns
    15  // 51 orgs on GET requests to /v3/organizations?order_by=name. It also
    16  // paginates, so page 2 can be requested with /v3/organizations?page=2&per_page=50.
    17  func AddFiftyOneOrgs(server *ghttp.Server) {
    18  	AddHandler(server,
    19  		http.MethodGet,
    20  		"/v3/organizations?order_by=name",
    21  		http.StatusOK,
    22  		[]byte(fmt.Sprintf(string(fixtureData("fifty-orgs-page-1.json")), server.URL())),
    23  	)
    24  
    25  	AddHandler(server,
    26  		http.MethodGet,
    27  		"/v3/organizations?page=2&per_page=50",
    28  		http.StatusOK,
    29  		fixtureData("fifty-orgs-page-2.json"),
    30  	)
    31  }
    32  
    33  func fixtureData(name string) []byte {
    34  	wd := os.Getenv("GOPATH")
    35  	fp := filepath.Join(wd, "src", "code.cloudfoundry.org", "cli", "integration", "helpers", "fixtures", name)
    36  	b, err := ioutil.ReadFile(fp)
    37  	Expect(err).ToNot(HaveOccurred())
    38  	return b
    39  }