-
Notifications
You must be signed in to change notification settings - Fork 0
/
assertions.go
68 lines (51 loc) · 1.41 KB
/
assertions.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
package consolesteps
import (
"fmt"
"strings"
"github.com/Netflix/go-expect"
"github.com/hinshun/vt10x"
"github.com/stretchr/testify/assert"
)
// TestingT is an interface wrapper around *testing.T.
type TestingT interface {
Errorf(format string, args ...interface{})
FailNow()
Log(args ...interface{})
Logf(format string, args ...interface{})
}
type tError struct {
err error
}
func (t *tError) Helper() {}
func (t *tError) Errorf(format string, args ...interface{}) {
t.err = fmt.Errorf(format, args...) // nolint: goerr113
}
func (t *tError) LastError() error {
return t.err
}
func teeError() *tError {
return &tError{}
}
// AssertState asserts console state.
func AssertState(t assert.TestingT, terminal vt10x.Terminal, expected string) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
actual := trimTailingSpaces(expect.StripTrailingEmptyLines(terminal.String()))
return assert.Equal(t, expected, actual)
}
// AssertStateRegex asserts console state.
func AssertStateRegex(t assert.TestingT, terminal vt10x.Terminal, expected string) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
actual := trimTailingSpaces(expect.StripTrailingEmptyLines(terminal.String()))
return assert.Regexp(t, expected, actual)
}
func trimTailingSpaces(out string) string {
lines := strings.Split(out, "\n")
for i, line := range lines {
lines[i] = strings.TrimRight(line, " ")
}
return strings.Join(lines, "\n")
}