-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathconnector_internal_test.go
More file actions
50 lines (39 loc) · 1015 Bytes
/
connector_internal_test.go
File metadata and controls
50 lines (39 loc) · 1015 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
50
package workflow
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/require"
)
type mockConnectorConsumer struct {
closed bool
closeErr error
}
func (m *mockConnectorConsumer) Recv(ctx context.Context) (*ConnectorEvent, Ack, error) {
return nil, nil, errors.New("not implemented")
}
func (m *mockConnectorConsumer) Close() error {
m.closed = true
return m.closeErr
}
func Test_connectorStreamer_Close(t *testing.T) {
t.Run("delegates to consumer.Close", func(t *testing.T) {
mock := &mockConnectorConsumer{}
cs := connectorStreamer{
consumer: mock,
}
err := cs.Close()
require.NoError(t, err)
require.True(t, mock.closed, "expected consumer.Close() to be called")
})
t.Run("propagates close error", func(t *testing.T) {
closeErr := errors.New("close failed")
mock := &mockConnectorConsumer{closeErr: closeErr}
cs := connectorStreamer{
consumer: mock,
}
err := cs.Close()
require.ErrorIs(t, err, closeErr)
require.True(t, mock.closed)
})
}