From 05b39385563687ed8e2385d7c38e680927fc0508 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 19 Jun 2019 17:02:34 -0600 Subject: [PATCH] Minor fixes to tests --- caddyhttp/httpserver/https_test.go | 5 +++-- caddyhttp/staticfiles/fileserver_test.go | 11 +++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/caddyhttp/httpserver/https_test.go b/caddyhttp/httpserver/https_test.go index 660f642b8..d5651998a 100644 --- a/caddyhttp/httpserver/https_test.go +++ b/caddyhttp/httpserver/https_test.go @@ -20,6 +20,7 @@ import ( "net" "net/http" "net/http/httptest" + "strconv" "testing" "github.com/mholt/caddy/caddytls" @@ -55,7 +56,7 @@ func TestRedirPlaintextHost(t *testing.T) { }, { 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", @@ -83,7 +84,7 @@ func TestRedirPlaintextHost(t *testing.T) { 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) } - 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) } diff --git a/caddyhttp/staticfiles/fileserver_test.go b/caddyhttp/staticfiles/fileserver_test.go index c74cc4010..200b6d6e1 100644 --- a/caddyhttp/staticfiles/fileserver_test.go +++ b/caddyhttp/staticfiles/fileserver_test.go @@ -432,7 +432,7 @@ func TestServeHTTPFailingFS(t *testing.T) { fsErr error expectedStatus int expectedErr error - expectedHeaders map[string]string + expectedHeaders map[string]struct{} }{ { fsErr: os.ErrNotExist, @@ -448,7 +448,7 @@ func TestServeHTTPFailingFS(t *testing.T) { fsErr: errCustom, expectedStatus: http.StatusServiceUnavailable, 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 if test.expectedHeaders != nil && len(test.expectedHeaders) > 0 { - for expectedKey, expectedVal := range test.expectedHeaders { - actualVal := responseRecorder.Header().Get(expectedKey) - if expectedVal != actualVal { - t.Errorf("Test %d: Expected header %s: %s, found %s", i, expectedKey, expectedVal, actualVal) + for expectedKey := range test.expectedHeaders { + if _, ok := responseRecorder.Header()[expectedKey]; !ok { + t.Errorf("Test %d: Expected header %s, but was missing", i, expectedKey) } } }