added first unit test
This commit is contained in:
parent
cd226af651
commit
5bf0b0b4e1
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,7 +27,7 @@ _testmain.go
|
|||||||
.idea/
|
.idea/
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
test/
|
testImages/
|
||||||
|
|
||||||
devconfig.ini
|
devconfig.ini
|
||||||
/main
|
/main
|
||||||
|
38
internal/pkg/localFileStructure/checksumCalculator_test.go
Normal file
38
internal/pkg/localFileStructure/checksumCalculator_test.go
Normal 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
1
test/md5testfile.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is a md5sum testfile to check the md5 wrapping code
|
Loading…
Reference in New Issue
Block a user