-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_test.go
80 lines (60 loc) · 1.61 KB
/
manager_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
74
75
76
77
78
79
80
package surveysteps
import (
"fmt"
"testing"
"time"
"github.com/cucumber/godog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.nhat.io/consolesteps"
"go.nhat.io/surveyexpect"
)
type TestingT struct {
error *surveyexpect.Buffer
log *surveyexpect.Buffer
clean func()
}
func (t *TestingT) Errorf(format string, args ...interface{}) {
_, _ = fmt.Fprintf(t.error, format, args...)
}
func (t *TestingT) Log(args ...interface{}) {
_, _ = fmt.Fprintln(t.log, args...)
}
func (t *TestingT) Logf(format string, args ...interface{}) {
_, _ = fmt.Fprintf(t.log, format, args...)
}
func (t *TestingT) FailNow() {
panic("failed")
}
func (t *TestingT) Cleanup(clean func()) {
t.clean = clean
}
func (t *TestingT) ErrorString() string {
return t.error.String()
}
func (t *TestingT) LogString() string {
return t.log.String()
}
func T() *TestingT {
return &TestingT{
error: new(surveyexpect.Buffer),
log: new(surveyexpect.Buffer),
clean: func() {},
}
}
func TestManager_ExpectationsWereNotMet(t *testing.T) {
t.Parallel()
testingT := T()
c := consolesteps.New(testingT)
s := New(testingT).WithConsole(c)
sc := &godog.Scenario{Id: "42", Name: "ExpectationsWereNotMet"}
c.NewConsole(sc)
require.NoError(t, s.expectPasswordAnswer("Enter password:", "password"))
<-time.After(50 * time.Millisecond)
s.close(sc)
expectedError := `in scenario "ExpectationsWereNotMet", there are remaining expectations that were not met:\
[\t\s]*Expect : Password Prompt\
[\t\s]*Message: "Enter password:"\
[\t\s]*Answer : "password"`
assert.Regexp(t, expectedError, testingT.ErrorString())
}