-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_checks_test.go
45 lines (34 loc) · 973 Bytes
/
api_checks_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
package healthcheck
import (
"context"
"github.com/stretchr/testify/require"
"io"
"testing"
"time"
)
func TestManualCheck2(t *testing.T) {
t.Parallel()
t.Run("check_constructor", func(t *testing.T) {
t.Parallel()
check := NewManual("sample")
require.Equal(t, "sample", check.id())
require.Equal(t, time.Hour, check.timeout())
require.ErrorIs(t, check.check(context.TODO()).Error, errInitial)
require.Len(t, check.log(), 0)
})
t.Run("set_and_unset_error", func(t *testing.T) {
t.Parallel()
check := NewManual("sample")
require.Error(t, check.check(context.TODO()).Error)
check.SetErr(nil)
require.NoError(t, check.check(context.TODO()).Error)
check.SetErr(io.EOF)
require.ErrorIs(t, check.check(context.TODO()).Error, io.EOF)
t.Run("check_logs", func(t *testing.T) {
records := check.log()
require.Len(t, records, 2)
require.NoError(t, records[0].Error)
require.ErrorIs(t, records[1].Error, errInitial)
})
})
}