Files
kubescape/internal/testutils/dir.go
rash1411 20557bc721 Update dir.go
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>
2025-04-27 01:29:04 +05:30

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)
}