bind: support multiple values (#2128)

Signed-off-by: Shengjing Zhu <i@zhsj.me>
This commit is contained in:
zhsj
2018-11-27 09:27:58 +08:00
committed by Matt Holt
parent 764c9ec956
commit 3a810c6502
8 changed files with 114 additions and 38 deletions

View File

@@ -19,6 +19,7 @@ import (
"net"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"github.com/mholt/caddy/caddytls"
@@ -28,7 +29,7 @@ func TestRedirPlaintextHost(t *testing.T) {
for i, testcase := range []struct {
Host string // used for the site config
Port string
ListenHost string
ListenHosts []string
RequestHost string // if different from Host
}{
{
@@ -43,13 +44,17 @@ func TestRedirPlaintextHost(t *testing.T) {
Port: "1234",
},
{
Host: "foohost",
ListenHost: "93.184.216.34",
Host: "foohost",
ListenHosts: []string{"93.184.216.34"},
},
{
Host: "foohost",
Port: "1234",
ListenHost: "93.184.216.34",
Host: "foohost",
Port: "1234",
ListenHosts: []string{"93.184.216.34"},
},
{
Host: "foohost",
ListenHosts: []string{"127.0.0.1", "127.0.0.2"},
},
{
Host: "foohost",
@@ -70,15 +75,15 @@ func TestRedirPlaintextHost(t *testing.T) {
Host: testcase.Host,
Port: testcase.Port,
},
ListenHost: testcase.ListenHost,
TLS: new(caddytls.Config),
ListenHosts: testcase.ListenHosts,
TLS: new(caddytls.Config),
})
// Check host and port
if actual, expected := cfg.Addr.Host, testcase.Host; actual != expected {
t.Errorf("Test %d: Expected redir config to have host %s but got %s", i, expected, actual)
}
if actual, expected := cfg.ListenHost, testcase.ListenHost; actual != expected {
if actual, expected := cfg.ListenHosts, testcase.ListenHosts; !reflect.DeepEqual(actual, expected) {
t.Errorf("Test %d: Expected redir config to have bindhost %s but got %s", i, expected, actual)
}
if actual, expected := cfg.Addr.Port, HTTPPort; actual != expected {