-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
46 lines (36 loc) · 984 Bytes
/
context_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
package trytryagain
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_IsCanceledContextError(t *testing.T) {
// given
testcases := map[string]bool{
`{"source":"","category":408,"code":"context_canceled","message":"Context canceled","data":"","retriable":true}`: true,
`Get "https://www.blah.com/something": context canceled`: true,
`context deadline exceeded`: true,
`not found`: false,
ErrContextCanceled.Error(): true,
}
for testcase, expected := range testcases {
// when
actual := IsCanceledContextError(fmt.Errorf(testcase))
// then
assert.Equal(t, expected, actual)
}
}
func Test_IsContextDone(t *testing.T) {
// given
ctx, cancel := context.WithCancel(context.Background())
// when
actual := IsContextDone(ctx)
// then
assert.False(t, actual)
// when
cancel()
actual = IsContextDone(ctx)
// then
assert.True(t, actual)
}