-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
async_test.go
38 lines (29 loc) · 891 Bytes
/
async_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
package utils
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestNewAsyncTask(t *testing.T) {
ctx := context.Background()
store := NewAsyncTaskStoreMemory()
at1, err := NewAsyncTask(ctx, store)
require.NoError(t, err)
at2, err := NewAsyncTask(ctx, store)
require.NoError(t, err)
require.NotEqual(t, at1.ID(), at2.ID())
require.Equal(t, at1.Status(), at2.Status())
require.Equal(t, AsyncTaskStatusPending, at2.Status())
err = at1.SetDone(ctx, "done")
require.NoError(t, err)
require.Equal(t, AsyncTaskStatusDone, at1.Status())
atr1, err := store.Get(ctx, at1.ID())
require.NoError(t, err)
require.Equal(t, "done", atr1.Data)
err = at2.SetError(ctx, "oho")
require.NoError(t, err)
require.Equal(t, AsyncTaskStatusFailed, at2.Status())
atr2, err := store.Get(ctx, at2.ID())
require.NoError(t, err)
require.Equal(t, "oho", atr2.Err)
}