-
Notifications
You must be signed in to change notification settings - Fork 0
/
race_test.go
49 lines (41 loc) · 877 Bytes
/
race_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
package asynks
import (
"errors"
"testing"
"github.com/golang-must/must"
)
func TestRace(t *testing.T) {
tasks := []TaskRace{
func() (interface{}, error) {
return 1, nil
},
func() (interface{}, error) {
return 2, nil
},
func() (interface{}, error) {
return 3, nil
},
}
tasksWithErrors := []TaskRace{
func() (interface{}, error) {
return nil, errors.New("don't cry")
},
func() (interface{}, error) {
return nil, errors.New("don't cry")
},
func() (interface{}, error) {
return nil, errors.New("don't cry")
},
}
t.Run("data exists in returns", func(t *testing.T) {
data, _ := Race(tasks)
must := must.New(t)
must.True(data == 1 || data == 2 || data == 3)
})
t.Run("task error produce error", func(t *testing.T) {
data, err := Race(tasksWithErrors)
must := must.New(t)
must.Nil(data)
must.NotNil(err)
})
}