added first unit test

This commit is contained in:
Philipp Häfelfinger 2019-03-13 00:14:19 +01:00
parent cd226af651
commit 5bf0b0b4e1
3 changed files with 40 additions and 1 deletions

2
.gitignore vendored
View File

@ -27,7 +27,7 @@ _testmain.go
.idea/ .idea/
*.log *.log
test/ testImages/
devconfig.ini devconfig.ini
/main /main

View File

@ -0,0 +1,38 @@
package localFileStructure
import (
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"testing"
)
func TestCalculateFileCheckSumsWithValidFile(t *testing.T) {
expectedSum := "2e7c66bd6657b1a8659ba05af26a0f7e"
sum, err := calculateFileCheckSums("../../../test/md5testfile.txt")
if err != nil {
t.Error(err)
}
if sum != expectedSum {
t.Errorf("wrong md5 sum provided: expected %s - got %s", expectedSum, sum)
}
}
func TestCalculateFileCheckSumsWithWrongPath(t *testing.T) {
hook := test.NewGlobal()
hook.Reset()
sum, err := calculateFileCheckSums("unknownPath")
if err == nil {
t.Error("there was no error using an invalid and unknown path.")
}
if sum != "" {
t.Error("found a checksum of an invalid file. This should not happen!")
}
if hook.LastEntry().Level != logrus.ErrorLevel {
t.Errorf("the error was not logged")
}
}

1
test/md5testfile.txt Normal file
View File

@ -0,0 +1 @@
This is a md5sum testfile to check the md5 wrapping code