mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
Fix: Correct runtime.Caller usage and handle error in CurrentDir() - Changed runtime.Caller(1) to runtime.Caller(0) to correctly fetch the current file's directory. - Added proper check for the 'ok' value returned by runtime.Caller. - Improved robustness by panicking if runtime information retrieval fails. Signed-off-by: rash1411 <107741585+rash1411@users.noreply.github.com>
16 lines
293 B
Go
16 lines
293 B
Go
package testutils
|
|
|
|
import (
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
// CurrentDir returns the directory of the file where this function is defined.
|
|
func CurrentDir() string {
|
|
_, filename, ok := runtime.Caller(0)
|
|
if !ok {
|
|
panic("failed to get current file info")
|
|
}
|
|
return filepath.Dir(filename)
|
|
}
|