MCPcopy Index your code
hub / github.com/rilldata/rill / TestHash

Function TestHash

runtime/pkg/gitutil/gitcmdwrapper_test.go:328–353  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

326}
327
328func TestHash(t *testing.T) {
329 t.Run("returns ErrRefNotFound for a missing ref", func(t *testing.T) {
330 tempDir := setupTestRepository(t)
331
332 _, err := Hash(context.Background(), tempDir, "refs/heads/does-not-exist")
333 require.ErrorIs(t, err, ErrRefNotFound)
334 })
335
336 t.Run("returns ErrRefNotFound for HEAD in an unborn repository", func(t *testing.T) {
337 tempDir := t.TempDir()
338 require.NoError(t, exec.Command("git", "init", tempDir).Run())
339 require.NoError(t, exec.Command("git", "-C", tempDir, "checkout", "-b", "main").Run())
340 setupGitConfig(t, tempDir)
341
342 _, err := Hash(context.Background(), tempDir, "HEAD")
343 require.ErrorIs(t, err, ErrRefNotFound)
344 })
345
346 t.Run("returns the commit hash for HEAD", func(t *testing.T) {
347 tempDir := setupTestRepository(t)
348
349 hash, err := Hash(context.Background(), tempDir, "HEAD")
350 require.NoError(t, err)
351 require.Len(t, hash, 40)
352 })
353}
354
355func TestIsCommitHash(t *testing.T) {
356 require.True(t, IsCommitHash(strings.Repeat("a1", 20)), "40-char SHA-1")

Callers

nothing calls this directly

Calls 6

HashFunction · 0.85
setupTestRepositoryFunction · 0.70
setupGitConfigFunction · 0.70
TempDirMethod · 0.65
RunMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected