github.com/snyk/vervet/v5@v5.11.1-0.20240202085829-ad4dd7fb6101/testdata/files.go (about) 1 // Package testdata provides utility functions for locating files used in 2 // tests. 3 package testdata 4 5 import ( 6 "fmt" 7 "path/filepath" 8 "runtime" 9 ) 10 11 // Path returns the absolute path, given a path relative to the testdata 12 // package directory. This function is intended for use in vervet tests. 13 func Path(path string) string { 14 _, thisFile, _, ok := runtime.Caller(0) 15 if !ok { 16 panic(fmt.Errorf("cannot locate caller")) 17 } 18 result, err := filepath.Abs(filepath.Dir(thisFile) + "/" + path) 19 if err != nil { 20 panic(err) 21 } 22 return result 23 }