From a5efa6975053f98a1c7a1529a4a610f26526972b Mon Sep 17 00:00:00 2001 From: Kristina Zabunova Date: Wed, 1 Jul 2015 08:42:13 -0700 Subject: [PATCH] =?UTF-8?q?unit=20test=20refactor=20in=20pkg/httputils=20a?= =?UTF-8?q?s=20suggested=20by=20vdemeester;=20using=20pattern=20if=20x=20:?= =?UTF-8?q?=3D=20=E2=80=A6;=20x=20=3D=3D=20nil=20{}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristina Zabunova (cherry picked from commit c3f1b2a5bd4a4330bcbad401c316af90925b99ad) --- httputils/httputils_test.go | 18 ++++++++---------- httputils/mimetype_test.go | 3 +-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/httputils/httputils_test.go b/httputils/httputils_test.go index 4704959..2214624 100644 --- a/httputils/httputils_test.go +++ b/httputils/httputils_test.go @@ -12,8 +12,7 @@ func TestDownload(t *testing.T) { } // Expected status code = 404 - _, err = Download("http://docker.com/abc1234567") - if err == nil { + if _, err = Download("http://docker.com/abc1234567"); err == nil { t.Errorf("Expected error to exist when Download(http://docker.com/abc1234567)") } } @@ -21,9 +20,7 @@ func TestDownload(t *testing.T) { func TestNewHTTPRequestError(t *testing.T) { errorMessage := "Some error message" httpResponse, _ := Download("http://docker.com") - err := NewHTTPRequestError(errorMessage, httpResponse) - - if err.Error() != errorMessage { + if err := NewHTTPRequestError(errorMessage, httpResponse); err.Error() != errorMessage { t.Errorf("Expected err to equal error Message") } } @@ -34,17 +31,18 @@ func TestParseServerHeader(t *testing.T) { t.Errorf("Should fail when header can not be parsed") } - serverHeader, err = ParseServerHeader("(bad header)") - if err.Error() != "Bad header: '/' missing" { + if serverHeader, err = ParseServerHeader("(bad header)"); err.Error() != "Bad header: '/' missing" { t.Errorf("Should fail when header can not be parsed") } - serverHeader, err = ParseServerHeader("(without/spaces)") - if err.Error() != "Bad header: Expected single space" { + if serverHeader, err = ParseServerHeader("(without/spaces)"); err.Error() != "Bad header: Expected single space" { t.Errorf("Should fail when header can not be parsed") } - serverHeader, err = ParseServerHeader("(header/with space)") + if serverHeader, err = ParseServerHeader("(header/with space)"); err != nil { + t.Errorf("Expected err to not exist when ParseServerHeader(\"(header/with space)\")") + } + if serverHeader.App != "(header" { t.Errorf("Expected serverHeader.App to equal \"(header\"") } diff --git a/httputils/mimetype_test.go b/httputils/mimetype_test.go index 90f0ece..9de433e 100644 --- a/httputils/mimetype_test.go +++ b/httputils/mimetype_test.go @@ -7,8 +7,7 @@ import ( func TestDetectContentType(t *testing.T) { input := []byte("That is just a plain text") - contentType, _, err := DetectContentType(input) - if err != nil || contentType != "text/plain" { + if contentType, _, err := DetectContentType(input); err != nil || contentType != "text/plain" { t.Errorf("TestDetectContentType failed") } }