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()) } }