improving code coverage

This commit is contained in:
Julien Neuhart
2018-04-05 10:36:38 +02:00
parent 15916e80e6
commit ee15a52001
8 changed files with 95 additions and 14 deletions

View File

@@ -43,8 +43,10 @@ func FindAuthorizedContentType(h http.Header) (ContentType, error) {
type notAuthorizedFileContentTypeError struct{}
const notAuthorizedFileContentTypeErrorMessage = "Unable to detect an authorized file content type"
func (e *notAuthorizedFileContentTypeError) Error() string {
return fmt.Sprintf("Unable to detect a file content type")
return notAuthorizedFileContentTypeErrorMessage
}
// SniffContentType tries to detect the content type of a file.

View File

@@ -1,6 +1,7 @@
package http
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
@@ -40,3 +41,18 @@ func TestSniffContentType(t *testing.T) {
t.Error("It should have been able to retrieve an authorized content type from a PDF file!")
}
}
func TestNotAuthorizedContentTypeError(t *testing.T) {
err := &notAuthorizedContentTypeError{}
message := fmt.Sprintf("Accepted values for 'Content-Type': %s, %s", OctetStreamContentType, MultipartFormDataContentType)
if err.Error() != message {
t.Errorf("Error returned a wrong message: got %s want %s", err.Error(), message)
}
}
func TestNotAuthorizedFileContentTypeError(t *testing.T) {
err := &notAuthorizedFileContentTypeError{}
if err.Error() != notAuthorizedFileContentTypeErrorMessage {
t.Errorf("Error returned a wrong message: got %s want %s", err.Error(), notAuthorizedFileContentTypeErrorMessage)
}
}