forked from kubernetes/ingress-nginx
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig_test.go
30 lines (26 loc) · 843 Bytes
/
config_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
package config
import (
"fmt"
"testing"
)
func TestBuildLogFormatUpstream(t *testing.T) {
testCases := []struct {
useProxyProtocol bool // use proxy protocol
curLogFormat string
expected string
}{
{true, logFormatUpstream, fmt.Sprintf("$proxy_protocol_addr - %s", logFormatUpstream)},
{false, logFormatUpstream, fmt.Sprintf("$remote_addr - %s", logFormatUpstream)},
{true, "my-log-format", "$proxy_protocol_addr - my-log-format"},
{false, "john-log-format", "$remote_addr - john-log-format"},
}
for _, testCase := range testCases {
cfg := NewDefault()
cfg.UseProxyProtocol = testCase.useProxyProtocol
cfg.LogFormatUpstream = testCase.curLogFormat
result := cfg.BuildLogFormatUpstream()
if result != testCase.expected {
t.Errorf(" expected %v but return %v", testCase.expected, result)
}
}
}