annotated repo_test
This commit is contained in:
parent
9297e1b90d
commit
fb911a4542
@ -24,6 +24,7 @@ func TestDefaultFullNodeRoundtrip(t *testing.T) {
|
|||||||
s = buf.String()
|
s = buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//stm: @NODE_CONFIG_003
|
||||||
c2, err := FromReader(strings.NewReader(s), DefaultFullNode())
|
c2, err := FromReader(strings.NewReader(s), DefaultFullNode())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ func TestDefaultMinerRoundtrip(t *testing.T) {
|
|||||||
s = buf.String()
|
s = buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//stm: @NODE_CONFIG_004
|
||||||
c2, err := FromReader(strings.NewReader(s), DefaultStorageMiner())
|
c2, err := FromReader(strings.NewReader(s), DefaultStorageMiner())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//stm: #unit
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -14,6 +15,7 @@ func TestDecodeNothing(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
//stm: @NODE_CONFIG_001
|
||||||
cfg, err := FromFile(os.DevNull, DefaultFullNode())
|
cfg, err := FromFile(os.DevNull, DefaultFullNode())
|
||||||
assert.Nil(err, "error should be nil")
|
assert.Nil(err, "error should be nil")
|
||||||
assert.Equal(DefaultFullNode(), cfg,
|
assert.Equal(DefaultFullNode(), cfg,
|
||||||
@ -21,6 +23,7 @@ func TestDecodeNothing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
//stm: @NODE_CONFIG_002
|
||||||
cfg, err := FromFile("./does-not-exist.toml", DefaultFullNode())
|
cfg, err := FromFile("./does-not-exist.toml", DefaultFullNode())
|
||||||
assert.Nil(err, "error should be nil")
|
assert.Nil(err, "error should be nil")
|
||||||
assert.Equal(DefaultFullNode(), cfg,
|
assert.Equal(DefaultFullNode(), cfg,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//stm: #unit
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -44,10 +45,12 @@ func TestImportLocal(t *testing.T) {
|
|||||||
b, err := testdata.ReadFile("testdata/payload.txt")
|
b, err := testdata.ReadFile("testdata/payload.txt")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
//stm: @CLIENT_IMPORT_003
|
||||||
root, err := a.ClientImportLocal(ctx, bytes.NewReader(b))
|
root, err := a.ClientImportLocal(ctx, bytes.NewReader(b))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEqual(t, cid.Undef, root)
|
require.NotEqual(t, cid.Undef, root)
|
||||||
|
|
||||||
|
//stm: @CLIENT_IMPORT_004
|
||||||
list, err := a.ClientListImports(ctx)
|
list, err := a.ClientListImports(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, list, 1)
|
require.Len(t, list, 1)
|
||||||
@ -68,6 +71,7 @@ func TestImportLocal(t *testing.T) {
|
|||||||
// retrieve as UnixFS.
|
// retrieve as UnixFS.
|
||||||
out1 := filepath.Join(dir, "retrieval1.data") // as unixfs
|
out1 := filepath.Join(dir, "retrieval1.data") // as unixfs
|
||||||
out2 := filepath.Join(dir, "retrieval2.data") // as car
|
out2 := filepath.Join(dir, "retrieval2.data") // as car
|
||||||
|
//stm: @CLIENT_IMPORT_005
|
||||||
err = a.ClientRetrieve(ctx, order, &api.FileRef{
|
err = a.ClientRetrieve(ctx, order, &api.FileRef{
|
||||||
Path: out1,
|
Path: out1,
|
||||||
})
|
})
|
||||||
@ -84,6 +88,7 @@ func TestImportLocal(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// open the CARv2 being custodied by the import manager
|
// open the CARv2 being custodied by the import manager
|
||||||
|
//stm: @CLIENT_IMPORT_006
|
||||||
orig, err := carv2.OpenReader(it.CARPath)
|
orig, err := carv2.OpenReader(it.CARPath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -94,6 +99,7 @@ func TestImportLocal(t *testing.T) {
|
|||||||
require.EqualValues(t, 1, exported.Version)
|
require.EqualValues(t, 1, exported.Version)
|
||||||
require.EqualValues(t, 2, orig.Version)
|
require.EqualValues(t, 2, orig.Version)
|
||||||
|
|
||||||
|
//stm: @CLIENT_IMPORT_007
|
||||||
origRoots, err := orig.Roots()
|
origRoots, err := orig.Roots()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, origRoots, 1)
|
require.Len(t, origRoots, 1)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//stm: #unit
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -35,11 +36,13 @@ func TestRoundtripUnixFS_Dense(t *testing.T) {
|
|||||||
defer os.Remove(carv2File) //nolint:errcheck
|
defer os.Remove(carv2File) //nolint:errcheck
|
||||||
|
|
||||||
// import a file to a Unixfs DAG using a CARv2 read/write blockstore.
|
// import a file to a Unixfs DAG using a CARv2 read/write blockstore.
|
||||||
|
//stm: @CLIENT_IMPORT_001, @CLIENT_BLOCKSTORE_001
|
||||||
bs, err := blockstore.OpenReadWrite(carv2File, nil,
|
bs, err := blockstore.OpenReadWrite(carv2File, nil,
|
||||||
carv2.ZeroLengthSectionAsEOF(true),
|
carv2.ZeroLengthSectionAsEOF(true),
|
||||||
blockstore.UseWholeCIDs(true))
|
blockstore.UseWholeCIDs(true))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
//stm: @CLIENT_IMPORT_001
|
||||||
root, err := buildUnixFS(ctx, bytes.NewBuffer(inputContents), bs, false)
|
root, err := buildUnixFS(ctx, bytes.NewBuffer(inputContents), bs, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEqual(t, cid.Undef, root)
|
require.NotEqual(t, cid.Undef, root)
|
||||||
@ -85,11 +88,13 @@ func TestRoundtripUnixFS_Filestore(t *testing.T) {
|
|||||||
dst := newTmpFile(t)
|
dst := newTmpFile(t)
|
||||||
defer os.Remove(dst) //nolint:errcheck
|
defer os.Remove(dst) //nolint:errcheck
|
||||||
|
|
||||||
|
//stm: @CLIENT_FS_001
|
||||||
root, err := a.createUnixFSFilestore(ctx, inputPath, dst)
|
root, err := a.createUnixFSFilestore(ctx, inputPath, dst)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEqual(t, cid.Undef, root)
|
require.NotEqual(t, cid.Undef, root)
|
||||||
|
|
||||||
// convert the CARv2 to a normal file again and ensure the contents match
|
// convert the CARv2 to a normal file again and ensure the contents match
|
||||||
|
//stm: @CLIENT_FS_002
|
||||||
fs, err := stores.ReadOnlyFilestore(dst)
|
fs, err := stores.ReadOnlyFilestore(dst)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer fs.Close() //nolint:errcheck
|
defer fs.Close() //nolint:errcheck
|
||||||
@ -116,6 +121,7 @@ func TestRoundtripUnixFS_Filestore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newTmpFile(t *testing.T) string {
|
func newTmpFile(t *testing.T) string {
|
||||||
|
//stm: @CLIENT_FS_003
|
||||||
f, err := os.CreateTemp("", "")
|
f, err := os.CreateTemp("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, f.Close())
|
require.NoError(t, f.Close())
|
||||||
@ -123,6 +129,7 @@ func newTmpFile(t *testing.T) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genInputFile(t *testing.T) (filepath string, contents []byte) {
|
func genInputFile(t *testing.T) (filepath string, contents []byte) {
|
||||||
|
//stm: @CLIENT_FS_004
|
||||||
s := strings.Repeat("abcde", 100)
|
s := strings.Repeat("abcde", 100)
|
||||||
tmp, err := os.CreateTemp("", "")
|
tmp, err := os.CreateTemp("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//stm: #unit
|
||||||
package full
|
package full
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -12,6 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMedian(t *testing.T) {
|
func TestMedian(t *testing.T) {
|
||||||
|
//stm: @REPO_GAS_001
|
||||||
require.Equal(t, types.NewInt(5), medianGasPremium([]GasMeta{
|
require.Equal(t, types.NewInt(5), medianGasPremium([]GasMeta{
|
||||||
{big.NewInt(5), build.BlockGasTarget},
|
{big.NewInt(5), build.BlockGasTarget},
|
||||||
}, 1))
|
}, 1))
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//stm: #unit
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -12,11 +13,13 @@ func genFsRepo(t *testing.T) (*FsRepo, func()) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//stm: @REPO_FS_001
|
||||||
repo, err := NewFS(path)
|
repo, err := NewFS(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//stm: @REPO_FS_002
|
||||||
err = repo.Init(FullNode)
|
err = repo.Init(FullNode)
|
||||||
if err != ErrRepoExists && err != nil {
|
if err != ErrRepoExists && err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -29,5 +32,6 @@ func genFsRepo(t *testing.T) (*FsRepo, func()) {
|
|||||||
func TestFsBasic(t *testing.T) {
|
func TestFsBasic(t *testing.T) {
|
||||||
repo, closer := genFsRepo(t)
|
repo, closer := genFsRepo(t)
|
||||||
defer closer()
|
defer closer()
|
||||||
|
//stm: @REPO_FS_003
|
||||||
basicTest(t, repo)
|
basicTest(t, repo)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//stm: #unit
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -6,5 +7,6 @@ import (
|
|||||||
|
|
||||||
func TestMemBasic(t *testing.T) {
|
func TestMemBasic(t *testing.T) {
|
||||||
repo := NewMemory(nil)
|
repo := NewMemory(nil)
|
||||||
|
//stm: @REPO_MEM_001
|
||||||
basicTest(t, repo)
|
basicTest(t, repo)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user