Files
gocryptotrader/internal/testing/utils/path.go
Gareth Kirwan 93c2d0122b Test: Internal exchange coverage (#1525)
* Test: Internal exchange coverage

* Tests: Rename exchange.TestInstance to Setup

This package function is either going to be imported and used as just exchange.Setup,
or more likely testexch.Setup.
This removes the Stutter of having
internal/testing/exchange.TestInstance which is implicit given the
package path
2024-05-07 15:14:02 +10:00

36 lines
826 B
Go

package path
import (
"errors"
"os"
"path/filepath"
"strings"
)
// Exported public errors
var (
ErrRootNotFound = errors.New("could not find root of gocryptotrader")
)
// RootPathFromCWD returns the system path to GoCryptoTrader from the current working directory
// Expects to find LICENSE file
func RootPathFromCWD() (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}
return RootPath(wd)
}
// RootPath returns the system path to GoCryptoTrader from a sub-directory path
func RootPath(p string) (string, error) {
parts := strings.Split(p, string(filepath.Separator))
for i := len(parts); i > 0; i-- {
dir := strings.Join(parts[:i], string(filepath.Separator))
if _, err := os.Stat(filepath.Join(dir, "LICENSE")); err == nil {
return dir, nil
}
}
return "", ErrRootNotFound
}