Skip to content

Instantly share code, notes, and snippets.

@dexterp
Last active April 11, 2024 19:19
Show Gist options
  • Save dexterp/d866ac2839807b525b7e0a386fecd325 to your computer and use it in GitHub Desktop.
Save dexterp/d866ac2839807b525b7e0a386fecd325 to your computer and use it in GitHub Desktop.
GO testtools.go
package testtools
import (
"path"
"path/filepath"
"runtime"
)
// FixtureDir returns the path to the fixture directory.
func FixtureDir() (fixturedir string) {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("Can not get filename")
}
fixturedir, err := filepath.Abs(path.Join(path.Dir(filename), "..", "..", "..", "fixtures"))
if err != nil {
panic(err)
}
return fixturedir
}
// TempDir returns the path to the localized tmp/ directory.
func TempDir() (tempdir string) {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("Can not get filename")
}
tempdir, err := filepath.Abs(path.Join(path.Dir(filename), "..", "..", "..", "tmp"))
if err != nil {
panic(err)
}
return tempdir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment