github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+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  func AddFiftyOneOrgs(server *ghttp.Server) {
    15  	AddHandler(server,
    16  		http.MethodGet,
    17  		"/v3/organizations?order_by=name",
    18  		http.StatusOK,
    19  		[]byte(fmt.Sprintf(string(fixtureData("fifty-orgs-page-1.json")), server.URL())),
    20  	)
    21  
    22  	AddHandler(server,
    23  		http.MethodGet,
    24  		"/v3/organizations?page=2&per_page=50",
    25  		http.StatusOK,
    26  		fixtureData("fifty-orgs-page-2.json"),
    27  	)
    28  }
    29  
    30  func fixtureData(name string) []byte {
    31  	wd := os.Getenv("GOPATH")
    32  	fp := filepath.Join(wd, "src", "code.cloudfoundry.org", "cli", "integration", "helpers", "fixtures", name)
    33  	b, err := ioutil.ReadFile(fp)
    34  	Expect(err).ToNot(HaveOccurred())
    35  	return b
    36  }