~bigbes/sr-ht-dolt

ref: dcdc9790d7fa085b5238eb39f196ccc8a2c0d5da sr-ht-dolt/storage/initempty_test.go -rw-r--r-- 1.3 KiB
dcdc9790 — Eugene Blikh mcpsrv: serve a stateless read-only MCP surface 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
package storage

import (
	"context"
	"os"
	"testing"

	"github.com/dolthub/dolt/go/store/hash"
	"github.com/dolthub/dolt/go/store/nbs"
	"github.com/dolthub/dolt/go/store/types"
)

// TestInitEmptyStore verifies that InitEmptyStore creates a directory whose NBS
// store root is the empty hash (no initial commit), so a client's first push
// lands as fast-forward-from-empty.
func TestInitEmptyStore(t *testing.T) {
	ctx := context.Background()
	root := t.TempDir()
	absPath := RepoDiskPath(root, "alice", "empty")

	if err := InitEmptyStore(ctx, absPath); err != nil {
		t.Fatalf("InitEmptyStore: %v", err)
	}

	info, err := os.Stat(absPath)
	if err != nil {
		t.Fatalf("stat store dir: %v", err)
	}
	if !info.IsDir() {
		t.Fatalf("expected %q to be a directory", absPath)
	}

	// Reopen via the same construction Cache.Get uses and confirm the store has
	// no root (the empty hash) — i.e. no commits were written.
	cs, err := nbs.NewLocalStore(ctx, types.Format_DOLT.VersionString(), absPath, defaultMemTableSize, nbs.NewUnlimitedMemQuotaProvider(), false)
	if err != nil {
		t.Fatalf("reopen store: %v", err)
	}
	defer cs.Close()

	rootHash, err := cs.Root(ctx)
	if err != nil {
		t.Fatalf("Root: %v", err)
	}
	if rootHash != (hash.Hash{}) {
		t.Fatalf("expected empty root hash, got %s", rootHash.String())
	}
}