github.com/w3security/vervet/v5@v5.3.1-0.20230618081846-5bd9b5d799dc/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 }