-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsource_test.go
More file actions
38 lines (33 loc) · 818 Bytes
/
source_test.go
File metadata and controls
38 lines (33 loc) · 818 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
package pipeline
import (
"context"
"errors"
"regexp"
"testing"
)
func TestSourceErrorHandling(t *testing.T) {
src := &sourceStub{
data: stringDataValues(3),
err: errors.New("source error"),
}
sink := new(sinkStub)
p := NewPipeline(testStage{t: t})
re := regexp.MustCompile("(?s).*pipeline input source: source error.*")
if err := p.Execute(context.TODO(), src, sink); err == nil || !re.MatchString(err.Error()) {
t.Errorf("Error did not match the expectation: %v", err)
}
}
type sourceStub struct {
index int
data []Data
err error
}
func (s *sourceStub) Next(context.Context) bool {
if s.err != nil || s.index == len(s.data) {
return false
}
s.index++
return true
}
func (s *sourceStub) Error() error { return s.err }
func (s *sourceStub) Data() Data { return s.data[s.index-1] }