-
Notifications
You must be signed in to change notification settings - Fork 2
/
md5sum_test.go
44 lines (41 loc) · 1021 Bytes
/
md5sum_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package utils
import (
"os"
"testing"
)
func TestMd5sum(t *testing.T) {
md5sum, err := Md5sum("Lorem ipsum dolor sit amet")
if err != nil {
t.Errorf("Unable to compute md5sum : %s", err)
}
sum := "fea80f2db003d4ebc4536023814aa885"
if md5sum != sum {
t.Errorf("Invalid md5sum got %s instead of %s", md5sum, sum)
}
return
}
func TestFileMd5sum(t *testing.T) {
path := os.TempDir() + "/" + "testFileMd5Sum"
f, err := os.Create(path)
if err != nil {
t.Errorf("Unable to open test file %s : %s", path, err)
}
_, err = f.Write([]byte("Lorem ipsum dolor sit amet"))
if err != nil {
t.Errorf("Unable to write test file %s : %s", path, err)
}
err = f.Close()
if err != nil {
t.Errorf("Unable to close test file %s : %s", path, err)
}
md5sum, err := FileMd5sum(path)
if err != nil {
t.Errorf("Unable to compute md5sum : %s", err)
}
sum := "fea80f2db003d4ebc4536023814aa885"
if md5sum != sum {
t.Errorf("Invalid md5sum got %s instead of %s", md5sum, sum)
}
err = os.Remove(path)
return
}