Skip to content

Commit

Permalink
test: improve loading of test fixtures (#306)
Browse files Browse the repository at this point in the history
Uses the Go embed functonality to access the test fixtures, and has the
useful side-effect of removing the last usage of the deprecated "ioutil"
package. Also an unused test fixture was removed.
  • Loading branch information
blgm authored Apr 23, 2024
1 parent 9ca5e22 commit 7452209
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 9 additions & 8 deletions api_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package brokerapi_test

import (
"fmt"
"io/ioutil"
"embed"
"io"
"path"
"testing"

Expand All @@ -31,14 +31,15 @@ func TestAPI(t *testing.T) {
RunSpecs(t, "API Suite")
}

//go:embed fixtures/*.json
var fixtures embed.FS

func fixture(name string) string {
filePath := path.Join("fixtures", name)
contents, err := ioutil.ReadFile(filePath)
if err != nil {
panic(fmt.Sprintf("Could not read fixture: %s", name))
}
GinkgoHelper()

return string(contents)
fh := must(fixtures.Open(path.Join("fixtures", name)))
defer fh.Close()
return string(must(io.ReadAll(fh)))
}

func uniqueID() string {
Expand Down
3 changes: 0 additions & 3 deletions fixtures/invalid_async_provision_error.json

This file was deleted.

0 comments on commit 7452209

Please sign in to comment.