From 5bf0b0b4e10bad20b6a30e710ba869eba3b53534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Wed, 13 Mar 2019 00:14:19 +0100 Subject: [PATCH] added first unit test --- .gitignore | 2 +- .../checksumCalculator_test.go | 38 +++++++++++++++++++ test/md5testfile.txt | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 internal/pkg/localFileStructure/checksumCalculator_test.go create mode 100644 test/md5testfile.txt diff --git a/.gitignore b/.gitignore index b89c180..8a41a08 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ _testmain.go .idea/ *.log -test/ +testImages/ devconfig.ini /main diff --git a/internal/pkg/localFileStructure/checksumCalculator_test.go b/internal/pkg/localFileStructure/checksumCalculator_test.go new file mode 100644 index 0000000..047d362 --- /dev/null +++ b/internal/pkg/localFileStructure/checksumCalculator_test.go @@ -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") + } +} diff --git a/test/md5testfile.txt b/test/md5testfile.txt new file mode 100644 index 0000000..2e87a5c --- /dev/null +++ b/test/md5testfile.txt @@ -0,0 +1 @@ +This is a md5sum testfile to check the md5 wrapping code \ No newline at end of file