-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
44 lines (38 loc) · 808 Bytes
/
example_test.go
File metadata and controls
44 lines (38 loc) · 808 Bytes
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 sumdiff_test
import (
"crypto/sha1"
"encoding/json"
"fmt"
"github.com/foolin/sumdiff"
"testing"
)
func TestExample(t *testing.T) {
path1 := "./test_data/a.txt"
path2 := "./test_data/b.txt"
//Compare
ok, res, err := sumdiff.Cmp(path1, path2)
fmt.Println("OK:", ok)
fmt.Println("Result:", toJson(res))
if err != nil {
fmt.Println("Error:", err)
}
fmt.Print("---------\n\n")
//Equal
ok, err = sumdiff.Equal(path1, path2)
fmt.Println("OK:", ok)
if err != nil {
fmt.Println("Error:", err)
}
fmt.Print("---------\n\n")
//Hash
res2, err := sumdiff.Hash(sha1.New(), path1, path2)
fmt.Println("Result:", toJson(res2))
if err != nil {
fmt.Println("Error:", err)
}
fmt.Print("---------\n\n")
}
func toJson(v any) string {
data, _ := json.Marshal(v)
return string(data)
}