forked from heroku/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_suite_test.go
73 lines (60 loc) · 1.5 KB
/
cli_suite_test.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
package main_test
import (
"bytes"
"os"
"path/filepath"
cli "github.com/heroku/cli"
"github.com/lunixbochs/vtclean"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"
"testing"
)
func TestCLI(t *testing.T) {
os.Setenv("TESTING", "1")
RegisterFailHandler(Fail)
testReports := os.Getenv("CIRCLE_TEST_REPORTS")
if testReports != "" {
path := filepath.Join(testReports, "go", "results.xml")
os.MkdirAll(filepath.Dir(path), 0755)
junitReporter := reporters.NewJUnitReporter(path)
RunSpecsWithDefaultAndCustomReporters(t, "CLI Suite", []Reporter{junitReporter})
} else {
RunSpecs(t, "CLI Suite")
}
}
var errLogPath = filepath.Join("tmp", "error.log")
var _ = BeforeSuite(func() {
cli.AppDir, _ = filepath.Abs(filepath.Join("tmp", "dev", "heroku"))
cli.CorePlugins.Path = filepath.Join(cli.AppDir, "lib")
cli.ExitFn = func(int) {}
os.MkdirAll(filepath.Dir(errLogPath), 0755)
cli.ErrLogPath = errLogPath
cli.ErrorArrow = "!"
})
var _ = AfterSuite(func() {
os.Remove(errLogPath)
cli.ShowCursor()
})
var _ = BeforeEach(func() {
cli.Stdout = new(bytes.Buffer)
cli.Stderr = new(bytes.Buffer)
})
var _ = AfterEach(func() {
cli.Stdout = os.Stdout
cli.Stderr = os.Stderr
})
func must(err error) {
if err != nil {
panic(err)
}
}
func stdout() string {
return stripcolor(cli.Stdout.(*bytes.Buffer).String())
}
func stderr() string {
return stripcolor(cli.Stderr.(*bytes.Buffer).String())
}
func stripcolor(in string) string {
return vtclean.Clean(in, false)
}