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

@@ -83,10 +83,12 @@ var filesTypes = map[ghttp.ContentType]Type{
ghttp.ZipContentType: OfficeType,
}
type fileTypeNotFound struct{}
type fileTypeNotFoundError struct{}
func (e *fileTypeNotFound) Error() string {
return "The file type was not found for the given 'Content-Type'"
const fileTypeNotFoundErrorMessage = "The file type was not found for the given 'Content-Type'"
func (e *fileTypeNotFoundError) Error() string {
return fileTypeNotFoundErrorMessage
}
// findFileType tries to detect what kind of file is the given file.
@@ -98,7 +100,7 @@ func findFileType(f *os.File) (Type, error) {
t, ok := filesTypes[ct]
if !ok {
return 999, &fileTypeNotFound{}
return 999, &fileTypeNotFoundError{}
}
return t, nil
@@ -124,17 +126,19 @@ var filesExtensions = map[Type]Ext{
OfficeType: OfficeExt,
}
type fileExtNotFound struct{}
type fileExtNotFoundError struct{}
func (e *fileExtNotFound) Error() string {
return "The file extension was not found for the given file type"
const fileExtNotFoundErrorMessage = "The file extension was not found for the given file type"
func (e *fileExtNotFoundError) Error() string {
return fileExtNotFoundErrorMessage
}
// reworkFilePath renames a file in the considered directory and adds its extension.
func reworkFilePath(workingDir string, f *File) (*File, error) {
ext, ok := filesExtensions[f.Type]
if !ok {
return nil, &fileExtNotFound{}
return nil, &fileExtNotFoundError{}
}
if ext != OfficeExt {

View File

@@ -50,3 +50,17 @@ func TestReworkFilePath(t *testing.T) {
os.RemoveAll(workingDir)
}
func TestFileTypeNotFoundError(t *testing.T) {
err := &fileTypeNotFoundError{}
if err.Error() != fileTypeNotFoundErrorMessage {
t.Errorf("Error returned a wrong message: got %s want %s", err.Error(), fileTypeNotFoundErrorMessage)
}
}
func TestFileExtNotFoundError(t *testing.T) {
err := &fileExtNotFoundError{}
if err.Error() != fileExtNotFoundErrorMessage {
t.Errorf("Error returned a wrong message: got %s want %s", err.Error(), fileExtNotFoundErrorMessage)
}
}