mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Increased test coverage of httputils to 70 %
Signed-off-by: Kristina Zabunova <triara.xiii@gmail.com>
(cherry picked from commit d71817464e
)
This commit is contained in:
parent
fdc73cc3fc
commit
b3f999e863
2 changed files with 73 additions and 0 deletions
59
pkg/httputils/httputils_test.go
Normal file
59
pkg/httputils/httputils_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package httputils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDownload(t *testing.T) {
|
||||
_, err := Download("http://docker.com")
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Expected error to not exist when Download(http://docker.com)")
|
||||
}
|
||||
|
||||
// Expected status code = 404
|
||||
_, err = Download("http://docker.com/abc1234567")
|
||||
if err == nil {
|
||||
t.Errorf("Expected error to exist when Download(http://docker.com/abc1234567)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewHTTPRequestError(t *testing.T) {
|
||||
errorMessage := "Some error message"
|
||||
httpResponse, _ := Download("http://docker.com")
|
||||
err := NewHTTPRequestError(errorMessage, httpResponse)
|
||||
|
||||
if err.Error() != errorMessage {
|
||||
t.Errorf("Expected err to equal error Message")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServerHeader(t *testing.T) {
|
||||
serverHeader, err := ParseServerHeader("bad header")
|
||||
if err.Error() != "Bad header: Failed regex match" {
|
||||
t.Errorf("Should fail when header can not be parsed")
|
||||
}
|
||||
|
||||
serverHeader, err = ParseServerHeader("(bad header)")
|
||||
if 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" {
|
||||
t.Errorf("Should fail when header can not be parsed")
|
||||
}
|
||||
|
||||
serverHeader, err = ParseServerHeader("(header/with space)")
|
||||
if serverHeader.App != "(header" {
|
||||
t.Errorf("Expected serverHeader.App to equal \"(header\"")
|
||||
}
|
||||
|
||||
if serverHeader.Ver != "with" {
|
||||
t.Errorf("Expected serverHeader.Ver to equal \"with\"")
|
||||
}
|
||||
|
||||
if serverHeader.OS != "header/with space" {
|
||||
t.Errorf("Expected serverHeader.OS to equal \"header/with space\"")
|
||||
}
|
||||
}
|
14
pkg/httputils/mimetype_test.go
Normal file
14
pkg/httputils/mimetype_test.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package httputils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDetectContentType(t *testing.T) {
|
||||
input := []byte("That is just a plain text")
|
||||
|
||||
contentType, _, err := DetectContentType(input)
|
||||
if err != nil || contentType != "text/plain" {
|
||||
t.Errorf("TestDetectContentType failed")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue