mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-15 07:16:28 +03:00
Minor fixes to tests
This commit is contained in:
parent
62b4553f7d
commit
05b3938556
2 changed files with 8 additions and 8 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mholt/caddy/caddytls"
|
"github.com/mholt/caddy/caddytls"
|
||||||
|
@ -55,7 +56,7 @@ func TestRedirPlaintextHost(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Host: "foohost",
|
Host: "foohost",
|
||||||
Port: HTTPSPort, // since this is the 'default' HTTPS port, should not be included in Location value
|
Port: strconv.Itoa(certmagic.HTTPSPort), // since this is the 'default' HTTPS port, should not be included in Location value
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Host: "*.example.com",
|
Host: "*.example.com",
|
||||||
|
@ -83,7 +84,7 @@ func TestRedirPlaintextHost(t *testing.T) {
|
||||||
if actual, expected := cfg.ListenHost, testcase.ListenHost; actual != expected {
|
if actual, expected := cfg.ListenHost, testcase.ListenHost; actual != expected {
|
||||||
t.Errorf("Test %d: Expected redir config to have bindhost %s but got %s", i, expected, actual)
|
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 {
|
if actual, expected := cfg.Addr.Port, strconv.Itoa(certmagic.HTTPPort); actual != expected {
|
||||||
t.Errorf("Test %d: Expected redir config to have port '%s' but got '%s'", i, expected, actual)
|
t.Errorf("Test %d: Expected redir config to have port '%s' but got '%s'", i, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -432,7 +432,7 @@ func TestServeHTTPFailingFS(t *testing.T) {
|
||||||
fsErr error
|
fsErr error
|
||||||
expectedStatus int
|
expectedStatus int
|
||||||
expectedErr error
|
expectedErr error
|
||||||
expectedHeaders map[string]string
|
expectedHeaders map[string]struct{}
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
fsErr: os.ErrNotExist,
|
fsErr: os.ErrNotExist,
|
||||||
|
@ -448,7 +448,7 @@ func TestServeHTTPFailingFS(t *testing.T) {
|
||||||
fsErr: errCustom,
|
fsErr: errCustom,
|
||||||
expectedStatus: http.StatusServiceUnavailable,
|
expectedStatus: http.StatusServiceUnavailable,
|
||||||
expectedErr: errCustom,
|
expectedErr: errCustom,
|
||||||
expectedHeaders: map[string]string{"Retry-After": "5"},
|
expectedHeaders: map[string]struct{}{"Retry-After": {}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,10 +477,9 @@ func TestServeHTTPFailingFS(t *testing.T) {
|
||||||
|
|
||||||
// check the headers - a special case for server under load
|
// check the headers - a special case for server under load
|
||||||
if test.expectedHeaders != nil && len(test.expectedHeaders) > 0 {
|
if test.expectedHeaders != nil && len(test.expectedHeaders) > 0 {
|
||||||
for expectedKey, expectedVal := range test.expectedHeaders {
|
for expectedKey := range test.expectedHeaders {
|
||||||
actualVal := responseRecorder.Header().Get(expectedKey)
|
if _, ok := responseRecorder.Header()[expectedKey]; !ok {
|
||||||
if expectedVal != actualVal {
|
t.Errorf("Test %d: Expected header %s, but was missing", i, expectedKey)
|
||||||
t.Errorf("Test %d: Expected header %s: %s, found %s", i, expectedKey, expectedVal, actualVal)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue