This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon_test.go
More file actions
58 lines (48 loc) · 1.34 KB
/
common_test.go
File metadata and controls
58 lines (48 loc) · 1.34 KB
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
package jpipe_test
import (
"testing"
"time"
"github.com/junitechnology/jpipe"
"github.com/stretchr/testify/assert"
)
func drainChannel[T any](channel *jpipe.Channel[T]) []T {
slice := []T{}
for value := range channel.ToGoChannel() {
slice = append(slice, value)
}
return slice
}
func readGoChannel[T any](channel <-chan T, n int) []T {
slice := []T{}
goChannel := channel
for i := 0; i < n; i++ {
slice = append(slice, <-goChannel)
}
return slice
}
func cancelPipeline(pipeline *jpipe.Pipeline) {
pipeline.Cancel(nil)
time.Sleep(time.Millisecond) // give some time for the cancellation to propagate
}
func assertChannelClosed[T any](t *testing.T, channel <-chan T, timeout time.Duration) {
select {
case _, open := <-channel:
assert.False(t, open, "Channel should be closed but a value was received")
case <-time.After(timeout):
assert.Fail(t, "Channel should be closed")
}
}
func assertChannelOpenButNoValue[T any](t *testing.T, channel <-chan T, timeout time.Duration) {
select {
case _, open := <-channel:
assert.False(t, open, "Channel should be open but a value should not be received")
case <-time.After(timeout):
}
}
func assertPipelineDone(t *testing.T, pipeline *jpipe.Pipeline, timeout time.Duration) {
select {
case <-pipeline.Done():
case <-time.After(timeout):
assert.Fail(t, "Pipeline should be done")
}
}