Skip to content

Commit

Permalink
chore: add base test
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZexiao committed Jul 5, 2022
1 parent 5af8fba commit e45787c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions piecestorage/storagemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ func (p *PieceStorageManager) ListStorageInfos() types.PieceStorageInfos {
S3Storage: s3,
}
}

func (p *PieceStorageManager) GetLength() int {
return len(p.storages)
}
69 changes: 69 additions & 0 deletions piecestorage/storagemgr_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,81 @@
package piecestorage

import (
"fmt"
"os"
"testing"

"github.com/filecoin-project/venus-market/v2/config"
"github.com/stretchr/testify/assert"
)

func TestFsAddPieceStorage(t *testing.T) {
psm, err := NewPieceStorageManager(&config.PieceStorage{})
assert.Nil(t, err)
path := os.TempDir()

ps, err := NewFsPieceStorage(&config.FsPieceStorage{
ReadOnly: false,
Path: path,
Name: "test",
})
assert.Nil(t, err)

err = psm.AddPieceStorage(ps)
assert.Nil(t, err)

l := psm.GetLength()
assert.Equal(t, 1, l)
}

func TestRmPieceStorage(t *testing.T) {
psm, err := NewPieceStorageManager(&config.PieceStorage{})
assert.Nil(t, err)
path := os.TempDir()
name := "test"

ps, err := NewFsPieceStorage(&config.FsPieceStorage{
ReadOnly: false,
Path: path,
Name: name,
})
assert.Nil(t, err)

err = psm.AddPieceStorage(ps)
assert.Nil(t, err)

err = psm.RemovePieceStorage("test2")
ErrPieceStorageNotFound := fmt.Errorf("storage test2 not exist")

assert.Equal(t, ErrPieceStorageNotFound, err)

err = psm.RemovePieceStorage(name)
assert.Nil(t, err)

l := psm.GetLength()
assert.Equal(t, 0, l)
}

func TestListStorageInfos(t *testing.T) {
psm, err := NewPieceStorageManager(&config.PieceStorage{})
assert.Nil(t, err)
path := os.TempDir()
name := "test"

ps, err := NewFsPieceStorage(&config.FsPieceStorage{
ReadOnly: false,
Path: path,
Name: name,
})
assert.Nil(t, err)

err = psm.AddPieceStorage(ps)
assert.Nil(t, err)

info := psm.ListStorageInfos()
assert.Equal(t, 1, len(info.FsStorage))
}

func TestRandSelect(t *testing.T) {
psm, err := NewPieceStorageManager(&config.PieceStorage{})
assert.Nil(t, err)
Expand Down

0 comments on commit e45787c

Please sign in to comment.