-
Notifications
You must be signed in to change notification settings - Fork 3
/
options_test.go
86 lines (70 loc) · 2.06 KB
/
options_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
package joehttp
import (
"crypto/tls"
"testing"
"time"
"github.com/go-joe/joe"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)
func joeConf(t *testing.T) *joe.Config {
joeConf := new(joe.Config)
require.NoError(t, joe.WithLogger(zaptest.NewLogger(t)).Apply(joeConf))
return joeConf
}
func TestWithLogger(t *testing.T) {
logger := zaptest.NewLogger(t)
conf, err := newConf("localhost:0", joeConf(t), []Option{
WithLogger(logger),
})
require.NoError(t, err)
assert.Equal(t, logger, conf.logger)
}
func TestWithTLS(t *testing.T) {
conf, err := newConf("localhost:0", joeConf(t), []Option{
WithTLS("foo.cert", "foo.key"),
})
require.NoError(t, err)
assert.Equal(t, "foo.cert", conf.certFile)
assert.Equal(t, "foo.key", conf.keyFile)
}
func TestWithTLSConfig(t *testing.T) {
tlsConf := &tls.Config{ServerName: "foo"}
conf, err := newConf("localhost:0", joeConf(t), []Option{
WithTLSConfig(tlsConf),
})
require.NoError(t, err)
assert.Equal(t, tlsConf, conf.tlsConf)
}
func TestWithTimeouts(t *testing.T) {
conf, err := newConf("localhost:0", joeConf(t), []Option{
WithTimeouts(42 * time.Second),
})
require.NoError(t, err)
assert.EqualValues(t, 42*time.Second, conf.readTimeout)
assert.EqualValues(t, 42*time.Second, conf.writeTimeout)
}
func TestWithReadTimeout(t *testing.T) {
conf, err := newConf("localhost:0", joeConf(t), []Option{
WithReadTimeout(42 * time.Second),
})
require.NoError(t, err)
assert.EqualValues(t, 42*time.Second, conf.readTimeout)
assert.EqualValues(t, 0, conf.writeTimeout)
}
func TestWithWriteTimeout(t *testing.T) {
conf, err := newConf("localhost:0", joeConf(t), []Option{
WithWriteTimeout(42 * time.Second),
})
require.NoError(t, err)
assert.EqualValues(t, 0, conf.readTimeout)
assert.EqualValues(t, 42*time.Second, conf.writeTimeout)
}
func TestWithTrustedHeader(t *testing.T) {
conf, err := newConf("localhost:0", joeConf(t), []Option{
WithTrustedHeader("x-real-ip"),
})
require.NoError(t, err)
assert.EqualValues(t, "x-real-ip", conf.trustedHeader)
}