~bigbes/sr-ht-dolt

ref: 5b00a51648a18e461bce9400d9fade6c9eeba28b sr-ht-dolt/browse/log_fromhash_test.go -rw-r--r-- 1.8 KiB
5b00a516 — Eugene Blikh browse: say which cells are actually NULL 5 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package browse

import (
	"context"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

// TestLogFromHashGarbage covers the MCP get_commit_log case: a caller-supplied
// cursor that does not even parse as a dolt hash must be an ordinary "not
// found" (errors.Is(err, ErrRefNotFound)), not an opaque internal error.
func TestLogFromHashGarbage(t *testing.T) {
	db := openFixture(t)
	ctx := context.Background()

	_, _, err := db.Log(ctx, "main", "not-a-hash", 10)
	require.Error(t, err)
	assert.ErrorIs(t, err, ErrRefNotFound)
}

// TestLogFromHashWellFormedButUnknown covers a fromHash that parses fine but
// names no commit this store has: same classification as a garbage string.
func TestLogFromHashWellFormedButUnknown(t *testing.T) {
	db := openFixture(t)
	ctx := context.Background()

	// 32 'a' characters is a syntactically valid (but non-existent) dolt hash.
	_, _, err := db.Log(ctx, "main", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 10)
	require.Error(t, err)
	assert.ErrorIs(t, err, ErrRefNotFound)
}

// TestLogFromHashValid confirms the happy path is untouched: a real hash
// still starts the walk there and pages as before.
func TestLogFromHashValid(t *testing.T) {
	db := openFixture(t)
	ctx := context.Background()

	commits, next, err := db.Log(ctx, "main", commitHash(t, msgInsert), 100)
	require.NoError(t, err)
	assert.Empty(t, next)

	want := []string{msgInsert, msgAddUser, msgInitial}
	require.Len(t, commits, len(want))
	for i, w := range want {
		assert.Equal(t, w, commits[i].Message)
	}
}

// TestLogFromHashEmpty confirms "" still means "start from ref's head".
func TestLogFromHashEmpty(t *testing.T) {
	db := openFixture(t)
	ctx := context.Background()

	commits, _, err := db.Log(ctx, "main", "", 100)
	require.NoError(t, err)
	require.NotEmpty(t, commits)
	assert.Equal(t, msgAddItem, commits[0].Message)
}