Skip to content

Commit

Permalink
Replace ioutil.ReadFile with embed for fixtures
Browse files Browse the repository at this point in the history
- fake_data.go tries to load files for testing, but has an assumption that code lives on the gopath
- this is no longer case with newer go versions
- use embed to embed the fixtures directory into the file which then allows relative path loading
  • Loading branch information
moleske authored and a-b committed Oct 21, 2022
1 parent 426fde6 commit c5839d5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions integration/helpers/fake_data.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package helpers

import (
"embed"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"

. "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.
Expand Down Expand Up @@ -81,9 +81,7 @@ func AddEmptyPaginatedResponse(server *ghttp.Server, path string) {
}

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)
b, err := content.ReadFile("fixtures/" + name)
Expect(err).ToNot(HaveOccurred())
return b
}

0 comments on commit c5839d5

Please sign in to comment.