unit test refactor in pkg/httputils as suggested by vdemeester; using pattern if x := …; x == nil {}
Signed-off-by: Kristina Zabunova <triara.xiii@gmail.com> (cherry picked from commit c3f1b2a5bd4a4330bcbad401c316af90925b99ad)
This commit is contained in:
parent
46454090b6
commit
a5efa69750
2 changed files with 9 additions and 12 deletions
|
@ -12,8 +12,7 @@ func TestDownload(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expected status code = 404
|
// Expected status code = 404
|
||||||
_, err = Download("http://docker.com/abc1234567")
|
if _, err = Download("http://docker.com/abc1234567"); err == nil {
|
||||||
if err == nil {
|
|
||||||
t.Errorf("Expected error to exist when Download(http://docker.com/abc1234567)")
|
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) {
|
func TestNewHTTPRequestError(t *testing.T) {
|
||||||
errorMessage := "Some error message"
|
errorMessage := "Some error message"
|
||||||
httpResponse, _ := Download("http://docker.com")
|
httpResponse, _ := Download("http://docker.com")
|
||||||
err := NewHTTPRequestError(errorMessage, httpResponse)
|
if err := NewHTTPRequestError(errorMessage, httpResponse); err.Error() != errorMessage {
|
||||||
|
|
||||||
if err.Error() != errorMessage {
|
|
||||||
t.Errorf("Expected err to equal error Message")
|
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")
|
t.Errorf("Should fail when header can not be parsed")
|
||||||
}
|
}
|
||||||
|
|
||||||
serverHeader, err = ParseServerHeader("(bad header)")
|
if serverHeader, err = ParseServerHeader("(bad header)"); err.Error() != "Bad header: '/' missing" {
|
||||||
if err.Error() != "Bad header: '/' missing" {
|
|
||||||
t.Errorf("Should fail when header can not be parsed")
|
t.Errorf("Should fail when header can not be parsed")
|
||||||
}
|
}
|
||||||
|
|
||||||
serverHeader, err = ParseServerHeader("(without/spaces)")
|
if serverHeader, err = ParseServerHeader("(without/spaces)"); err.Error() != "Bad header: Expected single space" {
|
||||||
if err.Error() != "Bad header: Expected single space" {
|
|
||||||
t.Errorf("Should fail when header can not be parsed")
|
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" {
|
if serverHeader.App != "(header" {
|
||||||
t.Errorf("Expected serverHeader.App to equal \"(header\"")
|
t.Errorf("Expected serverHeader.App to equal \"(header\"")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,7 @@ import (
|
||||||
func TestDetectContentType(t *testing.T) {
|
func TestDetectContentType(t *testing.T) {
|
||||||
input := []byte("That is just a plain text")
|
input := []byte("That is just a plain text")
|
||||||
|
|
||||||
contentType, _, err := DetectContentType(input)
|
if contentType, _, err := DetectContentType(input); err != nil || contentType != "text/plain" {
|
||||||
if err != nil || contentType != "text/plain" {
|
|
||||||
t.Errorf("TestDetectContentType failed")
|
t.Errorf("TestDetectContentType failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue