-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_setters_test.go
More file actions
43 lines (35 loc) · 1.22 KB
/
options_setters_test.go
File metadata and controls
43 lines (35 loc) · 1.22 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
package norm
import (
"context"
"testing"
"time"
)
type testLogger struct{}
func (testLogger) Debug(string, ...Field) {}
func (testLogger) Info(string, ...Field) {}
func (testLogger) Warn(string, ...Field) {}
func (testLogger) Error(string, ...Field) {}
type testMetrics struct{}
func (testMetrics) QueryDuration(_ time.Duration, _ string) {}
func (testMetrics) ConnectionCount(_ int32, _ int32) {}
func (testMetrics) ErrorCount(_ string) {}
func (testMetrics) CircuitStateChanged(_ string) {}
type testCache struct{}
func (testCache) Get(_ context.Context, _ string) ([]byte, bool, error) { return nil, false, nil }
func (testCache) Set(_ context.Context, _ string, _ []byte, _ time.Duration) error { return nil }
func (testCache) Invalidate(_ context.Context, _ ...string) error { return nil }
func TestOptionSetters(t *testing.T) {
o := defaultOptions()
WithLogger(testLogger{})(&o)
WithMetrics(testMetrics{})(&o)
WithCache(testCache{})(&o)
if _, ok := o.logger.(testLogger); !ok {
t.Fatalf("logger not set")
}
if _, ok := o.metrics.(testMetrics); !ok {
t.Fatalf("metrics not set")
}
if _, ok := o.cache.(testCache); !ok {
t.Fatalf("cache not set")
}
}