-
Notifications
You must be signed in to change notification settings - Fork 29
/
goflow_test.go
102 lines (87 loc) · 2.35 KB
/
goflow_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package goflow
import (
"errors"
"testing"
"time"
)
func TestNew(t *testing.T) {
gf := New()
if gf == nil {
t.Error("New() error")
}
}
func TestAdd1(t *testing.T) {
gf := New()
gf.Add("test", []string{"dep1"}, func(res map[string]interface{}) (interface{}, error) {
return "test result", nil
})
_, err := gf.Do()
if err.Error() != "Error: Function \"dep1\" not exists!" {
t.Error("Not existing function error")
}
}
func TestAdd2(t *testing.T) {
gf := New()
gf.Add("test", []string{"test"}, func(res map[string]interface{}) (interface{}, error) {
return "test result", nil
})
_, err := gf.Do()
if err.Error() != "Error: Function \"test\" depends of it self!" {
t.Error("Self denepdency error")
}
}
func TestDo1(t *testing.T) {
gf := New()
gf.Add("test", []string{}, func(res map[string]interface{}) (interface{}, error) {
return "test result", nil
})
res, err := gf.Do()
if err != nil || res["test"] != "test result" {
t.Error("Incorrect result")
}
}
func TestDo2(t *testing.T) {
var shouldBeFalse bool = false
gf := New()
gf.Add("first", []string{}, func(res map[string]interface{}) (interface{}, error) {
time.Sleep(time.Second * 1)
shouldBeFalse = true
return "first result", nil
})
gf.Add("second", []string{"first"}, func(res map[string]interface{}) (interface{}, error) {
shouldBeFalse = false
return "second result", nil
})
_, err := gf.Do()
if err != nil || shouldBeFalse == true {
t.Error("Incorrect goroutines execution order")
}
}
func TestDo3(t *testing.T) {
gf := New()
gf.Add("first", []string{}, func(res map[string]interface{}) (interface{}, error) {
return "first result", nil
})
gf.Add("second", []string{"first"}, func(res map[string]interface{}) (interface{}, error) {
return "second result", nil
})
res, err := gf.Do()
firstResult := res["first"]
secondResult := res["second"]
if err != nil || firstResult != "first result" || secondResult != "second result" {
t.Error("Incorrect results")
}
}
func TestDo4(t *testing.T) {
gf := New()
gf.Add("first", []string{}, func(res map[string]interface{}) (interface{}, error) {
return "first result", errors.New("some error")
})
gf.Add("second", []string{"first"}, func(res map[string]interface{}) (interface{}, error) {
return "second result", nil
})
_, err := gf.Do()
if err.Error() != "some error" {
t.Error("Incorrect error value")
}
}