Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/test/utils.go
2649 views
1
package test
2
3
import (
4
. "github.com/onsi/gomega"
5
"os"
6
"path"
7
"path/filepath"
8
"runtime"
9
"strings"
10
)
11
12
func FileToBytes(fileName string) ([]byte, error) {
13
_, thisFile, _, _ := runtime.Caller(0)
14
15
var (
16
urlPath string
17
err error
18
)
19
if strings.Contains(thisFile, "vendor") {
20
urlPath, err = filepath.Abs(path.Join(thisFile, "../../../../../..", "test", "data", fileName))
21
} else {
22
urlPath, err = filepath.Abs(path.Join(thisFile, "../..", "test", "data", fileName))
23
}
24
25
if err != nil {
26
return nil, err
27
}
28
29
Expect(urlPath).To(BeAnExistingFile())
30
31
return os.ReadFile(urlPath)
32
}
33
34