-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathteatest_test.go
52 lines (45 loc) · 1.34 KB
/
teatest_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
package teatest
import (
"fmt"
"strings"
"testing"
"testing/iotest"
"time"
tea "github.com/charmbracelet/bubbletea"
)
func TestWaitForErrorReader(t *testing.T) {
err := doWaitFor(iotest.ErrReader(fmt.Errorf("fake")), func(bts []byte) bool {
return true
}, WithDuration(time.Millisecond), WithCheckInterval(10*time.Microsecond))
if err == nil {
t.Fatal("expected an error, got nil")
}
if err.Error() != "WaitFor: fake" {
t.Fatalf("unexpected error: %s", err.Error())
}
}
func TestWaitForTimeout(t *testing.T) {
err := doWaitFor(strings.NewReader("nope"), func(bts []byte) bool {
return false
}, WithDuration(time.Millisecond), WithCheckInterval(10*time.Microsecond))
if err == nil {
t.Fatal("expected an error, got nil")
}
if err.Error() != "WaitFor: condition not met after 1ms. Last output:\nnope" {
t.Fatalf("unexpected error: %s", err.Error())
}
}
type m string
func (m m) Init() tea.Cmd { return nil }
func (m m) Update(tea.Msg) (tea.Model, tea.Cmd) { return m, nil }
func (m m) View() string { return string(m) }
func TestWaitFinishedWithTimeoutFn(t *testing.T) {
tm := NewTestModel(t, m("a"))
var timedOut bool
tm.WaitFinished(t, WithFinalTimeout(time.Nanosecond), WithTimeoutFn(func(testing.TB) {
timedOut = true
}))
if !timedOut {
t.Fatal("expected timedOut to be set")
}
}