Updated TestHostName to check port functionality added to server.hostName().
@@ -8,10 +8,12 @@ import (
func TestHostName(t *testing.T) {
testcases := []struct {
- request http.Request
- hostName string
+ request http.Request // request passed to server.hostName()
+ hostName string // config file hostname
+ port string // config file port
expected string
}{
+ // With no host or port set in config, the hostname should match that used in request uri
{
request: http.Request{
Host: "localhost",
@@ -19,16 +21,46 @@ func TestHostName(t *testing.T) {
hostName: "",
expected: "localhost",
},
+ // With a hostname set in config, that's what the resulting hostname should equal
{
request: http.Request{},
hostName: "cdn.tegola.io",
expected: "cdn.tegola.io",
},
+ // With a hostname set in config and port set to "none", resulting hostname should match
+ // config hostname.
+ {
+ request: http.Request{
+ Host: "localhost:8080",
+ },
+ hostName: "cdn.tegola.io",
+ port: "none",
+ expected: "cdn.tegola.io",
+ },
+ // With a hostname set in config, no port set in config, and an alternative port set
+ // in request uri, the resulting hostname should be <configHostName>:<requestPort>
+ {
+ request: http.Request{
+ Host: "localhost:8080",
+ },
+ hostName: "cdn.tegola.io",
+ expected: "cdn.tegola.io:8080",
+ },
+ // With hostname and port set in config, the result should be <configHostName>:<configPort>
+ {
+ request: http.Request{
+ Host: "localhost:8080",
+ },
+ hostName: "cdn.tegola.io",
+ port: "877",
+ expected: "cdn.tegola.io:877",
+ },
}
for i, tc := range testcases {
// set the package variable
HostName = tc.hostName
+ Port = tc.port
output := hostName(&tc.request)
if output != tc.expected {
