forked from charmbracelet/wish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelapsed_test.go
41 lines (34 loc) · 843 Bytes
/
elapsed_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
package elapsed
import (
"testing"
"time"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish/testsession"
gossh "golang.org/x/crypto/ssh"
)
var waitDuration = time.Second
func TestMiddleware(t *testing.T) {
t.Run("recover session", func(t *testing.T) {
b, err := setup(t).Output("")
requireNoError(t, err)
dur, err := time.ParseDuration(string(b))
requireNoError(t, err)
if dur < waitDuration {
t.Errorf("expected elapsed time to be at least 1s, got %v", dur)
}
})
}
func setup(tb testing.TB) *gossh.Session {
tb.Helper()
return testsession.New(tb, &ssh.Server{
Handler: MiddlewareWithFormat("%v")(func(s ssh.Session) {
time.Sleep(waitDuration)
}),
}, nil)
}
func requireNoError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatalf("expected no error, got %q", err.Error())
}
}