Skip to content

Commit

Permalink
Add a test case for SHA-256 support
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Dec 14, 2023
1 parent 00a6159 commit 57a0a57
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions git_sizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,3 +849,41 @@ func TestSubmodule(t *testing.T) {
assert.Equal(t, counts.Count32(2), h.UniqueBlobCount, "unique blob count")
assert.Equal(t, counts.Count32(3), h.MaxExpandedBlobCount, "max expanded blob count")
}

func TestSHA256(t *testing.T) {
t.Parallel()

ctx := context.Background()

t.Helper()

path, err := os.MkdirTemp("", "sha256")
require.NoError(t, err)

testRepo := testutils.TestRepo{Path: path}
defer testRepo.Remove(t)

// Don't use `GitCommand()` because the directory might not
// exist yet:
//nolint:gosec // `repo.Path` is a path that we created.

Check failure on line 868 in git_sizer_test.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:gosec // `repo.Path` is a path that we created.` is unused for linter "gosec" (nolintlint)
cmd := exec.Command("git", "init", "--object-format", "sha256", testRepo.Path)
cmd.Env = testutils.CleanGitEnv()
err = cmd.Run()
require.NoError(t, err)

timestamp := time.Unix(1112911993, 0)

testRepo.AddFile(t, "hello.txt", "Hello, world!\n")
cmd = testRepo.GitCommand(t, "commit", "-m", "initial")
testutils.AddAuthorInfo(cmd, &timestamp)
require.NoError(t, cmd.Run(), "creating initial commit")

cmd = testRepo.GitCommand(t, "commit", "-m", "initial", "--allow-empty")
testutils.AddAuthorInfo(cmd, &timestamp)
require.NoError(t, cmd.Run(), "creating commit")

repo := testRepo.Repository(t)

_, err = sizes.CollectReferences(ctx, repo, refGrouper{})
require.NoError(t, err)
}

0 comments on commit 57a0a57

Please sign in to comment.