-
Notifications
You must be signed in to change notification settings - Fork 1
/
fusion_test.go
80 lines (70 loc) 路 1.69 KB
/
fusion_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 fusion
import (
"context"
"errors"
"io"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestRunner_Run(t *testing.T) {
t.Parallel()
t.Run("NilStream", func(t *testing.T) {
fu := Runner{}
err := fu.Run(context.Background())
assert.Error(t, err)
})
t.Run("StreamErr", func(t *testing.T) {
fu := Runner{
Stream: &fakeStream{
OutFunc: func(ctx context.Context) (<-chan Msg, error) {
return nil, errors.New("failed")
},
},
}
err := fu.Run(context.Background())
assert.Error(t, err)
})
t.Run("NilChanFromStream", func(t *testing.T) {
fu := Runner{
Stream: &fakeStream{
OutFunc: func(ctx context.Context) (<-chan Msg, error) {
return nil, nil
},
},
}
err := fu.Run(context.Background())
assert.Error(t, err)
assert.Equal(t, io.EOF, err)
})
t.Run("StreamErr", func(t *testing.T) {
fu := Runner{
Stream: StreamFn(func(ctx context.Context) (*Msg, error) {
return nil, errors.New("stream error")
}),
Proc: ProcFn(func(ctx context.Context, stream <-chan Msg) error {
return errors.New("failed")
}),
DrainTime: 1 * time.Second,
}
err := fu.Run(context.Background())
assert.Error(t, err)
})
t.Run("Success", func(t *testing.T) {
fu := Runner{
Stream: StreamFn(func(ctx context.Context) (*Msg, error) {
return nil, io.EOF
}),
Proc: ProcFn(func(ctx context.Context, stream <-chan Msg) error {
return nil
}),
DrainTime: 1 * time.Second,
}
err := fu.Run(context.Background())
assert.NoError(t, err)
})
}
type fakeStream struct {
OutFunc func(ctx context.Context) (<-chan Msg, error)
}
func (f fakeStream) Out(ctx context.Context) (<-chan Msg, error) { return f.OutFunc(ctx) }