forked from appleboy/go-fcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
retry_test.go
43 lines (39 loc) · 810 Bytes
/
retry_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 fcm
import (
"errors"
"testing"
)
func TestRetry(t *testing.T) {
t.Run("retry=succcess", func(t *testing.T) {
var attempts int
err := retry(func() error {
attempts++
if attempts < 3 {
return connectionError("error")
}
return nil
}, 4)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if attempts != 3 {
t.Fatalf("expected 3 attempts\ngot: %d attempts", attempts)
}
})
t.Run("retry=false", func(t *testing.T) {
err := retry(func() error {
return errors.New("error")
}, 4)
if err == nil {
t.Fatalf("expected error: %v\ngot nil", err)
}
})
t.Run("retry=maxAttempts", func(t *testing.T) {
err := retry(func() error {
return connectionError("error")
}, 1)
if err == nil {
t.Fatalf("expected error: %v\ngot nil", err)
}
})
}