-
Notifications
You must be signed in to change notification settings - Fork 4
/
server_options_test.go
73 lines (64 loc) · 1.77 KB
/
server_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
// Copyright (c) Jim Lambert
// SPDX-License-Identifier: MIT
package gldap
import (
"crypto/tls"
"reflect"
"runtime"
"testing"
"time"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
)
func Test_WithLogger(t *testing.T) {
t.Parallel()
assert := assert.New(t)
opts := getConfigOpts(WithLogger(hclog.Default()))
testOpts := configDefaults()
testOpts.withLogger = hclog.Default()
assert.Equal(opts, testOpts)
}
func Test_WithTLSConfig(t *testing.T) {
t.Parallel()
assert := assert.New(t)
opts := getConfigOpts(WithTLSConfig(&tls.Config{}))
testOpts := configDefaults()
testOpts.withTLSConfig = &tls.Config{}
assert.Equal(opts, testOpts)
}
func Test_WithReadTimeout(t *testing.T) {
t.Parallel()
assert := assert.New(t)
timeout := 1 * time.Microsecond
opts := getConfigOpts(WithReadTimeout(timeout))
testOpts := configDefaults()
testOpts.withReadTimeout = timeout
assert.Equal(opts, testOpts)
}
func Test_WithWriteTimeout(t *testing.T) {
t.Parallel()
assert := assert.New(t)
timeout := 1 * time.Microsecond
opts := getConfigOpts(WithWriteTimeout(timeout))
testOpts := configDefaults()
testOpts.withWriteTimeout = timeout
assert.Equal(opts, testOpts)
}
func Test_WithDisablePanicRecovery(t *testing.T) {
t.Parallel()
assert := assert.New(t)
opts := getConfigOpts(WithDisablePanicRecovery())
testOpts := configDefaults()
testOpts.withDisablePanicRecovery = true
assert.Equal(opts, testOpts)
}
func Test_WitOnClose(t *testing.T) {
t.Parallel()
fn := func(int) {}
assert := assert.New(t)
opts := getConfigOpts(WithOnClose(fn))
testOpts := configDefaults()
testOpts.withOnClose = fn
assert.Equal(runtime.FuncForPC(reflect.ValueOf(opts.withOnClose).Pointer()).Name(),
runtime.FuncForPC(reflect.ValueOf(testOpts.withOnClose).Pointer()).Name())
}