-
Notifications
You must be signed in to change notification settings - Fork 444
/
directories.go
55 lines (45 loc) · 1.13 KB
/
directories.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package helpers
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"github.com/onsi/gomega"
)
func GlooDir() string {
return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "solo-io", "gloo")
}
func GlooTestContainersDir() string {
return filepath.Join(GlooDir(), "test", "kube2e", "containers")
}
func GlooInstallDir() string {
return filepath.Join(GlooDir(), "install")
}
func GlooHelmChartDir() string {
return filepath.Join(GlooInstallDir(), "helm", "gloo")
}
// returns absolute path to the currently executing directory
func GetCallerDirectory(skip ...int) (string, error) {
s := 1
if len(skip) > 0 {
s = skip[0] + 1
}
_, callerFile, _, ok := runtime.Caller(s)
if !ok {
return "", fmt.Errorf("failed to get runtime.Caller")
}
callerDir := filepath.Dir(callerFile)
return filepath.Abs(callerDir)
}
// returns absolute path to the currently executing directory
func MustReadFile(name string) []byte {
dir, err := GetCallerDirectory(1)
Must(err)
b, err := ioutil.ReadFile(filepath.Join(dir, name))
Must(err)
return b
}
func Must(err error) {
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred())
}