summaryrefslogtreecommitdiff
path: root/caddytest/caddytest.go
diff options
context:
space:
mode:
authorMark Sargent <99003+sarge@users.noreply.github.com>2020-03-18 07:39:01 +1300
committerGitHub <noreply@github.com>2020-03-17 12:39:01 -0600
commit3f48a2eb455167af8d77c5c4543bd17a80a93260 (patch)
tree3a104fabecf515b2d295f7e7240f506501ef3102 /caddytest/caddytest.go
parentf192ae5ea5c1e20e0c6aefc0772f0a92ee142f1e (diff)
caddyhttp: Add default SNI tests (#3146)
* added sni tests * set the default sni when there is no host to match * removed invalid sni test. Disabled tests that rely on host headers. * readded SNI tests. Added logging of config load times
Diffstat (limited to 'caddytest/caddytest.go')
-rw-r--r--caddytest/caddytest.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/caddytest/caddytest.go b/caddytest/caddytest.go
index 04b65ba..89e457c 100644
--- a/caddytest/caddytest.go
+++ b/caddytest/caddytest.go
@@ -45,6 +45,11 @@ type configLoadError struct {
func (e configLoadError) Error() string { return e.Response }
+func timeElapsed(start time.Time, name string) {
+ elapsed := time.Since(start)
+ log.Printf("%s took %s", name, elapsed)
+}
+
// InitServer this will configure the server with a configurion of a specific
// type. The configType must be either "json" or the adapter type.
func InitServer(t *testing.T, rawConfig string, configType string) {
@@ -83,6 +88,8 @@ func initServer(t *testing.T, rawConfig string, configType string) error {
client := &http.Client{
Timeout: time.Second * 2,
}
+
+ start := time.Now()
req, err := http.NewRequest("POST", fmt.Sprintf("http://localhost:%d/load", Default.AdminPort), strings.NewReader(rawConfig))
if err != nil {
t.Errorf("failed to create request. %s", err)
@@ -100,6 +107,8 @@ func initServer(t *testing.T, rawConfig string, configType string) error {
t.Errorf("unable to contact caddy server. %s", err)
return err
}
+ timeElapsed(start, "caddytest: config load time")
+
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
@@ -208,7 +217,7 @@ func AssertLoadError(t *testing.T, rawConfig string, configType string, expected
func AssertGetResponse(t *testing.T, requestURI string, statusCode int, expectedBody string) (*http.Response, string) {
resp, body := AssertGetResponseBody(t, requestURI, statusCode)
if !strings.Contains(body, expectedBody) {
- t.Errorf("expected response body \"%s\" but got \"%s\"", expectedBody, body)
+ t.Errorf("requesting \"%s\" expected response body \"%s\" but got \"%s\"", requestURI, expectedBody, body)
}
return resp, string(body)
}
@@ -229,7 +238,7 @@ func AssertGetResponseBody(t *testing.T, requestURI string, expectedStatusCode i
defer resp.Body.Close()
if expectedStatusCode != resp.StatusCode {
- t.Errorf("expected status code: %d but got %d", expectedStatusCode, resp.StatusCode)
+ t.Errorf("requesting \"%s\" expected status code: %d but got %d", requestURI, expectedStatusCode, resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
@@ -260,12 +269,12 @@ func AssertRedirect(t *testing.T, requestURI string, expectedToLocation string,
}
if expectedStatusCode != resp.StatusCode {
- t.Errorf("expected status code: %d but got %d", expectedStatusCode, resp.StatusCode)
+ t.Errorf("requesting \"%s\" expected status code: %d but got %d", requestURI, expectedStatusCode, resp.StatusCode)
}
loc, err := resp.Location()
if expectedToLocation != loc.String() {
- t.Errorf("expected location: \"%s\" but got \"%s\"", expectedToLocation, loc.String())
+ t.Errorf("requesting \"%s\" expected location: \"%s\" but got \"%s\"", requestURI, expectedToLocation, loc.String())
}
return resp