-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproviders_test.go
94 lines (75 loc) · 1.85 KB
/
providers_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package vshard_router_test
import (
"context"
"log/slog"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
vshardrouter "github.com/tarantool/go-vshard-router/v2"
)
var (
emptyMetrics = vshardrouter.EmptyMetrics{}
stdoutLogger = vshardrouter.StdoutLoggerf{}
)
func TestEmptyMetrics_RetryOnCall(t *testing.T) {
require.NotPanics(t, func() {
emptyMetrics.RetryOnCall("")
})
}
func TestEmptyMetrics_RequestDuration(t *testing.T) {
require.NotPanics(t, func() {
emptyMetrics.RequestDuration(time.Second, false, false)
})
}
func TestEmptyMetrics_CronDiscoveryEvent(t *testing.T) {
require.NotPanics(t, func() {
emptyMetrics.CronDiscoveryEvent(false, time.Second, "")
})
}
func TestStdoutLogger(t *testing.T) {
ctx := context.TODO()
require.NotPanics(t, func() {
stdoutLogger.Errorf(ctx, "")
})
require.NotPanics(t, func() {
stdoutLogger.Infof(ctx, "")
})
require.NotPanics(t, func() {
stdoutLogger.Warnf(ctx, "")
})
require.NotPanics(t, func() {
stdoutLogger.Debugf(ctx, "")
})
}
func TestNewSlogLogger(t *testing.T) {
var slogProvider vshardrouter.LogfProvider
require.NotPanics(t, func() {
slogProvider = vshardrouter.NewSlogLogger(nil)
})
require.Panics(t, func() {
slogProvider.Warnf(context.TODO(), "")
})
}
func TestSlogProvider(t *testing.T) {
ctx := context.Background()
// create new logger handler
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelError,
})
// create new SLogger instance
sLogger := slog.New(handler)
logProvider := vshardrouter.NewSlogLogger(sLogger)
require.NotPanics(t, func() {
logProvider.Infof(ctx, "test %s", "s")
})
require.NotPanics(t, func() {
logProvider.Warnf(ctx, "test %s", "s")
})
require.NotPanics(t, func() {
logProvider.Errorf(ctx, "test %s", "s")
})
require.NotPanics(t, func() {
logProvider.Debugf(ctx, "test %s", "s")
})
}