Skip to content

Commit

Permalink
Update tests to use hashers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroPatti committed Dec 10, 2023
1 parent f8df72a commit 724429f
Show file tree
Hide file tree
Showing 24 changed files with 893 additions and 708 deletions.
1 change: 1 addition & 0 deletions cache/disk/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ go_test(
"//cache:go_default_library",
"//cache/disk/casblob:go_default_library",
"//cache/disk/zstdimpl:go_default_library",
"//cache/hashing:go_default_library",
"//cache/httpproxy:go_default_library",
"//genproto/build/bazel/remote/execution/v2:go_default_library",
"//utils:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions cache/disk/casblob/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_test(
deps = [
":go_default_library",
"//cache/disk/zstdimpl:go_default_library",
"//cache/hashing:go_default_library",
"//utils:go_default_library",
],
)
8 changes: 3 additions & 5 deletions cache/disk/casblob/casblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package casblob_test

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
Expand All @@ -12,6 +10,7 @@ import (

"github.com/buchgr/bazel-remote/v2/cache/disk/casblob"
"github.com/buchgr/bazel-remote/v2/cache/disk/zstdimpl"
"github.com/buchgr/bazel-remote/v2/cache/hashing"
testutils "github.com/buchgr/bazel-remote/v2/utils"
)

Expand All @@ -35,7 +34,7 @@ func TestZstdFromLegacy(t *testing.T) {
t.Fatal(err)
}

data, hash := testutils.RandomDataAndHash(int64(size))
data, hash := testutils.RandomDataAndHash(int64(size), hashing.DefaultHasher)
dir := testutils.TempDir(t)
filename := fmt.Sprintf("%s/%s", dir, hash)
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0664)
Expand Down Expand Up @@ -73,8 +72,7 @@ func TestZstdFromLegacy(t *testing.T) {
t.Fatalf("Unexpected buf size %d, expected %d", buf.Len(), size)
}

h := sha256.Sum256(data)
hs := hex.EncodeToString(h[:])
hs := hashing.DefaultHasher.Hash(data)
if hs != hash {
t.Fatalf("Unexpected content sha %s, expected %s", hs, hash)
}
Expand Down
Loading

0 comments on commit 724429f

Please sign in to comment.