Skip to content

Commit 7ef3f00

Browse files
The127claude
andcommitted
refactor: the download tests name a digest in one place
Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: karo <karolin.kostial@gmail.com>
1 parent d2ef32a commit 7ef3f00

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎internal/download/pinned_test.go‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http/httptest"
99
"os"
1010
"path/filepath"
11+
"strings"
1112
"testing"
1213

1314
"github.com/stretchr/testify/assert"
@@ -16,25 +17,24 @@ import (
1617
"github.com/The127/miso/internal/download"
1718
)
1819

19-
// kept writes bytes into a store by hand and answers their digest.
20-
func kept(t *testing.T, dir, content string) string {
20+
// arrived is the digest bytes have once they are in.
21+
func arrived(t *testing.T, content string) string {
2122
t.Helper()
2223

2324
sum := sha256.Sum256([]byte(content))
24-
hash := hex.EncodeToString(sum[:])
25-
require.NoError(t, os.MkdirAll(filepath.Join(dir, "sha256"), 0o750))
26-
require.NoError(t, os.WriteFile(filepath.Join(dir, "sha256", hash), []byte(content), 0o600))
2725

28-
return "sha256:" + hash
26+
return "sha256:" + hex.EncodeToString(sum[:])
2927
}
3028

31-
// arrived is the digest bytes would have when they arrive.
32-
func arrived(t *testing.T, content string) string {
29+
// kept writes bytes into a store by hand and answers their digest.
30+
func kept(t *testing.T, dir, content string) string {
3331
t.Helper()
3432

35-
sum := sha256.Sum256([]byte(content))
33+
digest := arrived(t, content)
34+
require.NoError(t, os.MkdirAll(filepath.Join(dir, "sha256"), 0o750))
35+
require.NoError(t, os.WriteFile(filepath.Join(dir, "sha256", strings.TrimPrefix(digest, "sha256:")), []byte(content), 0o600))
3636

37-
return "sha256:" + hex.EncodeToString(sum[:])
37+
return digest
3838
}
3939

4040
func read(t *testing.T, path string) string {
@@ -71,8 +71,7 @@ func TestAPinnedFileThatIsNotThereIsDownloadedAndKept(t *testing.T) {
7171
server := serving(t, map[string]string{"/kernel.deb": "the kernel"})
7272
dir := t.TempDir()
7373
store := download.Open(dir, server.Client())
74-
sum := sha256.Sum256([]byte("the kernel"))
75-
digest := "sha256:" + hex.EncodeToString(sum[:])
74+
digest := arrived(t, "the kernel")
7675

7776
// act
7877
path, err := store.Pinned(context.Background(), server.URL+"/kernel.deb", digest)

0 commit comments

Comments
 (0)