1
1
package main
2
2
3
3
import (
4
- "encoding/hex"
5
4
"fmt"
6
5
"io"
7
6
"os"
@@ -19,7 +18,7 @@ func TestCreateFileHash(t *testing.T) {
19
18
if err != nil {
20
19
t .Fatalf ("Failed to create empty test file: %v" , err )
21
20
}
22
- emptyFile .Close ()
21
+ defer emptyFile .Close ()
23
22
24
23
contentFilePath := filepath .Join (tempDir , "content.txt" )
25
24
contentFile , err := os .Create (contentFilePath )
@@ -30,7 +29,7 @@ func TestCreateFileHash(t *testing.T) {
30
29
if _ , err := contentFile .WriteString (content ); err != nil {
31
30
t .Fatalf ("Failed to write to test file: %v" , err )
32
31
}
33
- contentFile .Close ()
32
+ defer contentFile .Close ()
34
33
35
34
hasher := xxh3 .New ()
36
35
@@ -49,7 +48,8 @@ func TestCreateFileHash(t *testing.T) {
49
48
if err != nil {
50
49
t .Fatalf ("Failed to create XXH3 hash for empty file: %v" , err )
51
50
}
52
- expectedEmptyHash := hex .EncodeToString (emptyHash .Sum (nil ))
51
+ hash = emptyHash .Sum128 ()
52
+ expectedEmptyHash := fmt .Sprintf ("%016x%016x" , hash .Hi , hash .Lo )
53
53
54
54
tests := []struct {
55
55
name string
@@ -79,7 +79,7 @@ func TestCreateFileHash(t *testing.T) {
79
79
name : "Directory instead of file" ,
80
80
filePath : tempDir ,
81
81
expectedHash : "" ,
82
- expectedErrMsg : "failed to compute hash " ,
82
+ expectedErrMsg : "hashing failed " ,
83
83
},
84
84
}
85
85
0 commit comments