Repository navigation
Expand file tree
/
Copy pathe2e.go
More file actions
102 lines (91 loc) · 2.16 KB
/
Copy pathe2e.go
File metadata and controls
102 lines (91 loc) · 2.16 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package testutil
import (
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"github.com/mitchellh/go-homedir"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
"github.com/sirupsen/logrus"
)
const (
DebugCommandPrefix = "\nCMD>"
DebugCommandPrefixWithDir = "\nCMD %s>"
DebugOutPrefix = "OUT: "
DebugErrPrefix = "ERR: "
DefaultE2ETestTimeout = 60 // in seconds
)
type CmdOpts struct {
Args []string
WorkingDirectory string
}
func Hasura(opts CmdOpts) *Session {
var hasuraBinaryPath = CLIBinaryPath
args := append([]string{"--skip-update-check"}, opts.Args...)
cmd := exec.Command(hasuraBinaryPath, args...)
if opts.WorkingDirectory != "" {
cmd.Dir = opts.WorkingDirectory
}
session, err := Start(
cmd,
NewPrefixedWriter(DebugOutPrefix, GinkgoWriter),
NewPrefixedWriter(DebugErrPrefix, GinkgoWriter),
)
Expect(err).NotTo(HaveOccurred())
return session
}
func RunCommandAndSucceed(opts CmdOpts) *Session {
session := Hasura(opts)
Eventually(session, DefaultE2ETestTimeout).Should(Exit(0))
return session
}
func RandDirName() string {
file, err := ioutil.TempFile("", "cli-e2e-*")
if err != nil {
log.Fatal(err)
}
defer func() {
file.Close()
defer os.Remove(file.Name())
}()
return file.Name()
}
func RemoveDir(dirName string) {
err := os.RemoveAll(dirName)
if err != nil {
log.Println(err)
}
}
func CloseWithLogOnErr(closer io.Closer) {
err := closer.Close()
if err == nil {
return
}
logger := logrus.New()
logger.Out = GinkgoWriter
logger.Error(err)
}
func RemoveHasuraConfigHomeDirectory() {
homeDir, err := homedir.Dir()
Expect(err).ShouldNot(HaveOccurred())
err = os.RemoveAll(filepath.Join(homeDir, ".hasura"))
Expect(err).ShouldNot(HaveOccurred())
}
// to run commands other than hasura
func Command(cmdPath string, opts CmdOpts) *Session {
cmd := exec.Command(cmdPath, opts.Args...)
if opts.WorkingDirectory != "" {
cmd.Dir = opts.WorkingDirectory
}
session, err := Start(
cmd,
NewPrefixedWriter(DebugOutPrefix, GinkgoWriter),
NewPrefixedWriter(DebugErrPrefix, GinkgoWriter),
)
Expect(err).NotTo(HaveOccurred())
return session
}