Skip to content

Commit 2eaed57

Browse files
committed
fix failing tests
1 parent e38502e commit 2eaed57

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

hash_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"encoding/hex"
54
"fmt"
65
"io"
76
"os"
@@ -19,7 +18,7 @@ func TestCreateFileHash(t *testing.T) {
1918
if err != nil {
2019
t.Fatalf("Failed to create empty test file: %v", err)
2120
}
22-
emptyFile.Close()
21+
defer emptyFile.Close()
2322

2423
contentFilePath := filepath.Join(tempDir, "content.txt")
2524
contentFile, err := os.Create(contentFilePath)
@@ -30,7 +29,7 @@ func TestCreateFileHash(t *testing.T) {
3029
if _, err := contentFile.WriteString(content); err != nil {
3130
t.Fatalf("Failed to write to test file: %v", err)
3231
}
33-
contentFile.Close()
32+
defer contentFile.Close()
3433

3534
hasher := xxh3.New()
3635

@@ -49,7 +48,8 @@ func TestCreateFileHash(t *testing.T) {
4948
if err != nil {
5049
t.Fatalf("Failed to create XXH3 hash for empty file: %v", err)
5150
}
52-
expectedEmptyHash := hex.EncodeToString(emptyHash.Sum(nil))
51+
hash = emptyHash.Sum128()
52+
expectedEmptyHash := fmt.Sprintf("%016x%016x", hash.Hi, hash.Lo)
5353

5454
tests := []struct {
5555
name string
@@ -79,7 +79,7 @@ func TestCreateFileHash(t *testing.T) {
7979
name: "Directory instead of file",
8080
filePath: tempDir,
8181
expectedHash: "",
82-
expectedErrMsg: "failed to compute hash",
82+
expectedErrMsg: "hashing failed",
8383
},
8484
}
8585

0 commit comments

Comments
 (0)