mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 c3f1b2a5bd
)
This commit is contained in:
parent
b3f999e863
commit
f753f6d597
2 changed files with 9 additions and 12 deletions
|
@ -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\"")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue