Skip to content

Instantly share code, notes, and snippets.

@r002
Created June 11, 2021 18:40
Show Gist options
  • Save r002/b9bd9fd8c814b53f2d981fcde1f3445d to your computer and use it in GitHub Desktop.
Save r002/b9bd9fd8c814b53f2d981fcde1f3445d to your computer and use it in GitHub Desktop.
Change to ./ root in Go tests to read files (eg. go test .\service\ -v -count=1)
func init() {
_, filename, _, _ := runtime.Caller(0)
fmt.Println(">> Initializing testing:", filename)
dir := path.Join(path.Dir(filename), "..")
err := os.Chdir(dir)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment