Repository navigation
Expand file tree
/
Copy pathoptions_test.go
More file actions
106 lines (77 loc) · 1.96 KB
/
Copy pathoptions_test.go
File metadata and controls
106 lines (77 loc) · 1.96 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
package bootstrap
import (
"context"
"log/slog"
"reflect"
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/tecnickcom/nurago/pkg/logutil"
"github.com/tecnickcom/nurago/pkg/metrics"
)
func TestWithContext(t *testing.T) {
t.Parallel()
cfg := &config{}
type empty struct{}
v := context.WithValue(t.Context(), empty{}, "")
WithContext(v)(cfg)
require.Equal(t, v, cfg.context)
}
func TestWithLogConfig(t *testing.T) {
t.Parallel()
cfg := &config{}
lc := logutil.DefaultConfig()
WithLogConfig(lc)(cfg)
require.Equal(t, lc, cfg.logConfig)
require.True(t, cfg.logConfigSet)
require.NotNil(t, cfg.createLoggerFunc)
}
func TestWithLogger(t *testing.T) {
t.Parallel()
cfg := &config{}
l := slog.Default()
WithLogger(l)(cfg)
require.NotNil(t, cfg.createLoggerFunc)
ll := cfg.createLoggerFunc()
require.Equal(t, l, ll)
}
func TestWithCreateLoggerFunc(t *testing.T) {
t.Parallel()
cfg := &config{}
v := func() *slog.Logger {
return nil
}
WithCreateLoggerFunc(v)(cfg)
require.Equal(t, reflect.ValueOf(v).Pointer(), reflect.ValueOf(cfg.createLoggerFunc).Pointer())
}
func TestWithCreateMetricsClientFunc(t *testing.T) {
t.Parallel()
cfg := &config{}
v := func() (metrics.Client, error) {
return nil, nil //nolint:nilnil
}
WithCreateMetricsClientFunc(v)(cfg)
require.Equal(t, reflect.ValueOf(v).Pointer(), reflect.ValueOf(cfg.createMetricsClientFunc).Pointer())
}
func TestWithShutdownTimeout(t *testing.T) {
t.Parallel()
cfg := defaultConfig()
v := 17 * time.Second
WithShutdownTimeout(v)(cfg)
require.Equal(t, v, cfg.shutdownTimeout)
}
func TestWithShutdownWaitGroup(t *testing.T) {
t.Parallel()
cfg := defaultConfig()
v := &sync.WaitGroup{}
WithShutdownWaitGroup(v)(cfg)
require.Equal(t, v, cfg.shutdownWaitGroup)
}
func TestWithShutdownSignalChan(t *testing.T) {
t.Parallel()
cfg := defaultConfig()
v := make(chan struct{})
WithShutdownSignalChan(v)(cfg)
require.Equal(t, v, cfg.shutdownSignalChan)
}