Repository navigation
Expand file tree
/
Copy pathoptions_test.go
More file actions
81 lines (61 loc) · 1.69 KB
/
Copy pathoptions_test.go
File metadata and controls
81 lines (61 loc) · 1.69 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
package httpreverseproxy
import (
"log/slog"
"net/http"
"net/http/httputil"
"reflect"
"testing"
"github.com/stretchr/testify/require"
"github.com/tecnickcom/nurago/pkg/redact"
)
type testHTTPClient struct{}
func (thc *testHTTPClient) Do(_ *http.Request) (*http.Response, error) {
return nil, nil //nolint:nilnil
}
func TestWithHTTPClient(t *testing.T) {
t.Parallel()
v := &testHTTPClient{}
c := &Client{}
WithHTTPClient(v)(c)
require.Equal(t, reflect.ValueOf(v).Pointer(), reflect.ValueOf(c.httpClient).Pointer())
}
func TestWithReverseProxy(t *testing.T) {
t.Parallel()
v := &httputil.ReverseProxy{}
c := &Client{}
WithReverseProxy(v)(c)
require.Equal(t, reflect.ValueOf(v).Pointer(), reflect.ValueOf(c.proxy).Pointer())
}
func TestWithLogger(t *testing.T) {
t.Parallel()
l := slog.Default()
c := &Client{}
WithLogger(l)(c)
require.Equal(t, l, c.logger)
}
func TestWithPathParam(t *testing.T) {
t.Parallel()
c := &Client{}
WithPathParam("upstream")(c)
require.Equal(t, "upstream", c.pathParam)
// An empty name falls back to the default.
WithPathParam("")(c)
require.Equal(t, defaultPathParam, c.pathParam)
}
func TestWithRedactFn(t *testing.T) {
t.Parallel()
sentinel := func(_ []byte) string { return "REDACTED" }
c := &Client{redactFn: redact.Default().BytesToString}
WithRedactFn(sentinel)(c)
require.Equal(t, "REDACTED", c.redactFn(nil))
// A nil fn is ignored and keeps the previously set function.
WithRedactFn(nil)(c)
require.Equal(t, "REDACTED", c.redactFn(nil))
}
func TestWithLaxBasePath(t *testing.T) {
t.Parallel()
c := &Client{}
require.False(t, c.laxBasePath, "base-path check is strict by default")
WithLaxBasePath()(c)
require.True(t, c.laxBasePath)
}