-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe_test.go
59 lines (56 loc) · 1.37 KB
/
pipe_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
package executors
import (
"errors"
"fmt"
"math/rand/v2"
"reflect"
"testing"
)
func mockStatefulTask() (TaskFunc, Stateful) {
fn := Pipe(func(s Stateful) (Stateful, error) {
if rand.IntN(100) < 50 {
return s, errors.New("random_error")
}
return fmt.Sprintf("mock: %v", s), nil
}, func(s Stateful) (Stateful, error) {
if rand.IntN(100) < 50 {
return s, errors.New("random_error")
}
return fmt.Sprintf("mock: %v", s), nil
}, func(s Stateful) (Stateful, error) {
if rand.IntN(100) < 50 {
return s, errors.New("random_error")
}
return fmt.Sprintf("mock: %v", s), nil
})
sin := fmt.Sprintf("mock%d", 1)
return fn, sin
}
func TestPipe(t *testing.T) {
fn1, s1 := mockStatefulTask()
fn := Pipe(func(s Stateful) (Stateful, error) {
if rand.IntN(100) < 50 {
return s, errors.New("random_error")
}
return fmt.Sprintf("pipe1: %v", s), nil
}, func(s Stateful) (Stateful, error) {
if rand.IntN(100) < 50 {
return s, errors.New("random_error")
}
return fmt.Sprintf("pipe2: %v", s), nil
}, func(s Stateful) (Stateful, error) {
if rand.IntN(100) < 50 {
return s, errors.New("random_error")
}
return s1, nil
}, fn1)
outs, errCount, err := RunTest(fn, 1)
if err != nil {
t.Error(err)
}
os, ok := outs.(string)
if !ok {
t.Errorf("outs: %v, ty: %v", outs, reflect.TypeOf(outs))
}
fmt.Printf("outs: %v, errCount: %v\n", ToJSON(os), errCount)
}