From db3a956d52bf23cc5201fe98bc9c9787d3b32c2d Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 13 Jan 2016 18:49:25 -0700 Subject: [PATCH] Couple more tests to ensure right method is being used --- acme/http_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/acme/http_test.go b/acme/http_test.go index 3e04e950..33a48a33 100644 --- a/acme/http_test.go +++ b/acme/http_test.go @@ -8,9 +8,10 @@ import ( ) func TestHTTPHeadUserAgent(t *testing.T) { - var ua string + var ua, method string ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ua = r.Header.Get("User-Agent") + method = r.Method })) defer ts.Close() @@ -19,15 +20,19 @@ func TestHTTPHeadUserAgent(t *testing.T) { t.Fatal(err) } + if method != "HEAD" { + t.Errorf("Expected method to be HEAD, got %s", method) + } if !strings.Contains(ua, ourUserAgent) { t.Errorf("Expected User-Agent to contain '%s', got: '%s'", ourUserAgent, ua) } } func TestHTTPGetUserAgent(t *testing.T) { - var ua string + var ua, method string ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ua = r.Header.Get("User-Agent") + method = r.Method })) defer ts.Close() @@ -37,15 +42,19 @@ func TestHTTPGetUserAgent(t *testing.T) { } res.Body.Close() + if method != "GET" { + t.Errorf("Expected method to be GET, got %s", method) + } if !strings.Contains(ua, ourUserAgent) { t.Errorf("Expected User-Agent to contain '%s', got: '%s'", ourUserAgent, ua) } } func TestHTTPPostUserAgent(t *testing.T) { - var ua string + var ua, method string ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ua = r.Header.Get("User-Agent") + method = r.Method })) defer ts.Close() @@ -55,6 +64,9 @@ func TestHTTPPostUserAgent(t *testing.T) { } res.Body.Close() + if method != "POST" { + t.Errorf("Expected method to be POST, got %s", method) + } if !strings.Contains(ua, ourUserAgent) { t.Errorf("Expected User-Agent to contain '%s', got: '%s'", ourUserAgent, ua) }