Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenReadWriteFile: add test #324

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions v2/blockstore/readwrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,41 @@ func TestReadWrite_ReWritingCARv1WithIdentityCidIsIdenticalToOriginalWithOptions
require.Equal(t, wantSum, gotSum)
}

func TestReadWriteOpenFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

dir := t.TempDir() // auto cleanup
f, err := ioutil.TempFile(dir, "")
require.NoError(t, err)

root := blocks.NewBlock([]byte("foo"))

bs, err := blockstore.OpenReadWriteFile(f, []cid.Cid{root.Cid()})
require.NoError(t, err)

err = bs.Put(ctx, root)
require.NoError(t, err)

roots, err := bs.Roots()
require.NoError(t, err)
_, err = bs.Has(ctx, roots[0])
require.NoError(t, err)
_, err = bs.Get(ctx, roots[0])
require.NoError(t, err)
_, err = bs.GetSize(ctx, roots[0])
require.NoError(t, err)

err = bs.Finalize()
require.NoError(t, err)

_, err = f.Seek(0, 0)
require.NoError(t, err) // file should not be closed, let the caller do it
MichaelMure marked this conversation as resolved.
Show resolved Hide resolved

err = f.Close()
require.NoError(t, err)
}

func TestBlockstore_IdentityCidWithEmptyDataIsIndexed(t *testing.T) {
p := path.Join(t.TempDir(), "car-id-cid-empty.carv2")
var noData []byte
Expand Down