2017-02-27 10:00:31 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildLogFormatUpstream(t *testing.T) {
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
useProxyProtocol bool // use proxy protocol
|
2017-03-03 12:02:36 +00:00
|
|
|
curLogFormat string
|
2017-02-27 10:00:31 +00:00
|
|
|
expected string
|
|
|
|
}{
|
2017-03-04 19:46:45 +00:00
|
|
|
{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"},
|
2017-02-27 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
2017-03-04 19:46:45 +00:00
|
|
|
cfg := NewDefault()
|
|
|
|
cfg.UseProxyProtocol = testCase.useProxyProtocol
|
|
|
|
cfg.LogFormatUpstream = testCase.curLogFormat
|
|
|
|
result := cfg.BuildLogFormatUpstream()
|
2017-02-27 10:00:31 +00:00
|
|
|
if result != testCase.expected {
|
|
|
|
t.Errorf(" expected %v but return %v", testCase.expected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|