-
Notifications
You must be signed in to change notification settings - Fork 29
/
cmd.go
80 lines (71 loc) · 1.61 KB
/
cmd.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
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
package testrunner
import (
"bytes"
"fmt"
"os/exec"
"path"
"testing"
)
type End2EndCmd struct {
AppID string
TestCase TestCase
Test *testing.T
}
func (e *End2EndCmd) CreateConfigSource() error {
cmd := fmt.Sprintf(
"./dist/e2e create-configsource --app-id %s --config-source %s --config-override \"%s\"",
e.AppID,
e.resolvePath(e.TestCase.AuthgearYAMLSource.Extend),
e.TestCase.AuthgearYAMLSource.Override,
)
if _, err := e.execCmd(cmd); err != nil {
return err
}
return nil
}
func (e *End2EndCmd) ImportUsers(jsonPath string) error {
cmd := fmt.Sprintf(
"./dist/e2e import-users %s --app-id %s",
e.resolvePath(jsonPath),
e.AppID,
)
if _, err := e.execCmd(cmd); err != nil {
return err
}
return nil
}
func (e *End2EndCmd) ExecuteCustomSQL(sqlPath string) error {
cmd := fmt.Sprintf(
"./dist/e2e exec-sql --app-id %s --custom-sql \"%s\"",
e.AppID,
e.resolvePath(sqlPath),
)
if _, err := e.execCmd(cmd); err != nil {
return err
}
return nil
}
func (e *End2EndCmd) GetLinkOTPCodeByClaim(claim string, value string) (string, error) {
cmd := fmt.Sprintf(
"./dist/e2e link-otp-code %s %s --app-id %s",
claim,
value,
e.AppID,
)
return e.execCmd(cmd)
}
func (e *End2EndCmd) resolvePath(p string) string {
return path.Join("./tests/authflow/", path.Dir(e.TestCase.Path), p)
}
func (e *End2EndCmd) execCmd(cmd string) (string, error) {
var errb bytes.Buffer
execCmd := exec.Command("sh", "-c", cmd)
execCmd.Stderr = &errb
execCmd.Dir = "../../"
output, err := execCmd.Output()
if err != nil {
e.Test.Errorf(errb.String())
return "", err
}
return string(output), nil
}