-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathdisplay_test.go
More file actions
49 lines (40 loc) · 896 Bytes
/
display_test.go
File metadata and controls
49 lines (40 loc) · 896 Bytes
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
package jsonstream
import (
"context"
"io"
"testing"
"time"
"github.com/docker/cli/cli/streams"
"gotest.tools/v3/assert"
)
func TestDisplay(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
client, server := io.Pipe()
t.Cleanup(func() {
assert.NilError(t, server.Close())
})
go func() {
for range 100 {
select {
case <-ctx.Done():
assert.NilError(t, server.Close(), "failed to close jsonmessage server")
return
default:
time.Sleep(100 * time.Millisecond)
}
}
}()
streamCtx, cancelStream := context.WithCancel(context.Background())
t.Cleanup(cancelStream)
done := make(chan error)
go func() {
done <- DisplayStream(streamCtx, client, streams.NewOut(io.Discard))
}()
cancelStream()
select {
case <-time.After(time.Second * 3):
case err := <-done:
assert.ErrorIs(t, err, context.Canceled)
}
}