2023-12-13 15:10:20 +01:00
|
|
|
// Package mock implements mock functions used in unit-tests.
|
2019-10-20 16:02:28 +02:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Path returns the absolute path to the specified mock file.
|
|
|
|
func Path(filename string) string {
|
|
|
|
|
|
|
|
// determine the path of this file during runtime
|
|
|
|
_, thisfile, _, _ := runtime.Caller(0)
|
|
|
|
|
2020-11-12 01:33:31 +01:00
|
|
|
// compute the mock path
|
2019-10-20 16:02:28 +02:00
|
|
|
file, err := filepath.Abs(
|
|
|
|
path.Join(
|
|
|
|
filepath.Dir(thisfile),
|
|
|
|
"../../mocks",
|
|
|
|
filename,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
if err != nil {
|
2020-11-12 01:33:31 +01:00
|
|
|
panic(fmt.Errorf("failed to resolve mock path: %v", err))
|
2019-10-20 16:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return file
|
|
|
|
}
|