Set host and port on address if specified via flag (fixes #888)

Also fixed a few typos and renamed caddyfile.ServerBlocks() to
caddyfile.Parse().
This commit is contained in:
Matthew Holt
2016-06-20 18:25:31 -06:00
parent 33aba7eb91
commit 937654d1e0
8 changed files with 54 additions and 15 deletions
+25 -1
View File
@@ -1,6 +1,11 @@
package httpserver
import "testing"
import (
"strings"
"testing"
"github.com/mholt/caddy/caddyfile"
)
func TestStandardizeAddress(t *testing.T) {
for i, test := range []struct {
@@ -112,3 +117,22 @@ func TestAddressString(t *testing.T) {
}
}
}
func TestInspectServerBlocksWithCustomDefaultPort(t *testing.T) {
Port = "9999"
filename := "Testfile"
ctx := newContext().(*httpContext)
input := strings.NewReader(`localhost`)
sblocks, err := caddyfile.Parse(filename, input, nil)
if err != nil {
t.Fatalf("Expected no error setting up test, got: %v", err)
}
_, err = ctx.InspectServerBlocks(filename, sblocks)
if err != nil {
t.Fatalf("Didn't expect an error, but got: %v", err)
}
addr := ctx.keysToSiteConfigs["localhost"].Addr
if addr.Port != Port {
t.Errorf("Expected the port on the address to be set, but got: %#v", addr)
}
}