-
Notifications
You must be signed in to change notification settings - Fork 11
/
task_test.go
43 lines (35 loc) · 855 Bytes
/
task_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
package async
import (
"errors"
"testing"
"time"
"github.com/reugn/async/internal/assert"
"github.com/reugn/async/internal/util"
)
func TestTask_Success(t *testing.T) {
task := NewTask(func() (string, error) {
time.Sleep(10 * time.Millisecond)
return "ok", nil
})
res, err := task.Call().Join()
assert.Equal(t, "ok", res)
assert.IsNil(t, err)
}
func TestTask_SuccessPtr(t *testing.T) {
task := NewTask(func() (*string, error) {
time.Sleep(10 * time.Millisecond)
return util.Ptr("ok"), nil
})
res, err := task.Call().Join()
assert.Equal(t, "ok", *res)
assert.IsNil(t, err)
}
func TestTask_Failure(t *testing.T) {
task := NewTask(func() (*string, error) {
time.Sleep(10 * time.Millisecond)
return nil, errors.New("error")
})
res, err := task.Call().Join()
assert.IsNil(t, res)
assert.ErrorContains(t, err, "error")
}