This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail upload if it uses more then available space
Before upload, check that more then the disk has more than the minimum free space. Upload up to the size limit that would exceed the available space. Fixes #179
- Loading branch information
Showing
9 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package blob_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"testing" | ||
|
||
"github.com/filecoin-project/motion/blob" | ||
"github.com/gammazero/fsutil/disk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWriteOK(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
|
||
store := blob.NewLocalStore(tmpDir, 0) | ||
buf := []byte("This is a test") | ||
readCloser := io.NopCloser(bytes.NewReader(buf)) | ||
|
||
desc, err := store.Put(context.Background(), readCloser) | ||
require.NoError(t, err) | ||
require.NotNil(t, desc) | ||
require.Equal(t, uint64(len(buf)), desc.Size) | ||
} | ||
|
||
func TestInsufficientSpace(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
usage, err := disk.Usage(tmpDir) | ||
require.NoError(t, err) | ||
|
||
store := blob.NewLocalStore(tmpDir, usage.Free+blob.Gib) | ||
readCloser := io.NopCloser(bytes.NewReader([]byte("This is a test"))) | ||
|
||
_, err = store.Put(context.Background(), readCloser) | ||
require.ErrorIs(t, err, blob.ErrNotEnoughSpace) | ||
} | ||
|
||
func TestWriteTooLarge(t *testing.T) { | ||
tmpDir := t.TempDir() | ||
usage, err := disk.Usage(tmpDir) | ||
require.NoError(t, err) | ||
|
||
store := blob.NewLocalStore(tmpDir, usage.Free-5*blob.Kib) | ||
|
||
buf := make([]byte, 32*blob.Kib) | ||
readCloser := io.NopCloser(bytes.NewReader(buf)) | ||
|
||
_, err = store.Put(context.Background(), readCloser) | ||
require.ErrorIs(t, err, blob.ErrBlobTooLarge) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters