findProjectRoot finds the absolute path to the project root by looking for go.mod
()
| 41 | |
| 42 | // findProjectRoot finds the absolute path to the project root by looking for go.mod |
| 43 | func findProjectRoot() (string, error) { |
| 44 | // Start from current working directory |
| 45 | wd, err := os.Getwd() |
| 46 | if err != nil { |
| 47 | return "", err |
| 48 | } |
| 49 | |
| 50 | // Walk up the directory tree looking for go.mod |
| 51 | dir := wd |
| 52 | for { |
| 53 | goModPath := filepath.Join(dir, "go.mod") |
| 54 | if _, err := os.Stat(goModPath); err == nil { |
| 55 | // Found go.mod, this is our project root |
| 56 | return dir, nil |
| 57 | } |
| 58 | |
| 59 | parent := filepath.Dir(dir) |
| 60 | if parent == dir { |
| 61 | // Reached filesystem root without finding go.mod |
| 62 | break |
| 63 | } |
| 64 | dir = parent |
| 65 | } |
| 66 | return "", os.ErrNotExist |
| 67 | } |
| 68 | |
| 69 | // Root returns the absolute path to the testdata directory |
| 70 | func (p *TestDataProvider) Root() string { |
no outgoing calls
no test coverage detected