-
Notifications
You must be signed in to change notification settings - Fork 8
/
options_test.go
72 lines (52 loc) · 1.45 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
// SPDX-License-Identifier: Apache-2.0
package frisbee
import (
"crypto/tls"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/loopholelabs/logging"
)
func TestWithoutOptions(t *testing.T) {
t.Parallel()
options := loadOptions()
assert.Equal(t, time.Minute*3, options.KeepAlive)
assert.NotNil(t, options.Logger)
assert.Nil(t, options.TLSConfig)
}
func TestWithOptions(t *testing.T) {
t.Parallel()
option := WithOptions(Options{
KeepAlive: time.Minute * 6,
Logger: nil,
TLSConfig: &tls.Config{},
})
options := loadOptions(option)
assert.Equal(t, time.Minute*6, options.KeepAlive)
assert.NotNil(t, options.Logger)
assert.Equal(t, &tls.Config{}, options.TLSConfig)
}
func TestDisableOptions(t *testing.T) {
t.Parallel()
option := WithOptions(Options{
KeepAlive: -1,
})
options := loadOptions(option)
assert.Equal(t, time.Duration(-1), options.KeepAlive)
assert.NotNil(t, options.Logger)
assert.Nil(t, options.TLSConfig)
}
func TestIndividualOptions(t *testing.T) {
t.Parallel()
logger := logging.Test(t, logging.Noop, t.Name())
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
keepAliveOption := WithKeepAlive(time.Minute * 6)
loggerOption := WithLogger(logger)
TLSOption := WithTLS(tlsConfig)
options := loadOptions(keepAliveOption, loggerOption, TLSOption)
assert.Equal(t, time.Minute*6, options.KeepAlive)
assert.Equal(t, logger, options.Logger)
assert.Equal(t, tlsConfig, options.TLSConfig)
}