1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-25 06:58:18 +08:00

test for pinning semantics

This commit is contained in:
Jeromy
2015-03-18 16:48:06 -07:00
parent 6bf341302c
commit 3bf7d5c27e
2 changed files with 40 additions and 1 deletions

View File

@ -152,3 +152,41 @@ func TestPinnerBasic(t *testing.T) {
t.Fatal("could not find recursively pinned node")
}
}
func TestDuplicateSemantics(t *testing.T) {
dstore := dssync.MutexWrap(ds.NewMapDatastore())
bstore := blockstore.NewBlockstore(dstore)
bserv, err := bs.New(bstore, offline.Exchange(bstore))
if err != nil {
t.Fatal(err)
}
dserv := mdag.NewDAGService(bserv)
// TODO does pinner need to share datastore with blockservice?
p := NewPinner(dstore, dserv)
a, _ := randNode()
_, err = dserv.Add(a)
if err != nil {
t.Fatal(err)
}
// pin is recursively
err = p.Pin(a, true)
if err != nil {
t.Fatal(err)
}
// pinning directly should fail
err = p.Pin(a, false)
if err == nil {
t.Fatal("expected direct pin to fail")
}
// pinning recursively again should succeed
err = p.Pin(a, true)
if err != nil {
t.Fatal(err)
}
}

View File

@ -48,6 +48,7 @@ test_expect_success "file no longer pinned" '
# we expect the welcome files to show up here
echo "$HASH_WELCOME_DOCS" >expected2 &&
ipfs refs -r "$HASH_WELCOME_DOCS" >>expected2 &&
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >> expected2 &&
sort expected2 >expected_sorted2 &&
ipfs pin ls -type=recursive >actual2 &&
sort actual2 >actual_sorted2 &&
@ -127,7 +128,6 @@ test_expect_success "pin something directly" '
test_expect_success "'ipfs pin ls -type=direct' is correct" '
echo "$DIRECTPIN" >directpinexpected &&
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>directpinexpected &&
sort directpinexpected >dp_exp_sorted &&
ipfs pin ls -type=direct >directpinout &&
sort directpinout >dp_out_sorted &&
@ -137,6 +137,7 @@ test_expect_success "'ipfs pin ls -type=direct' is correct" '
test_expect_success "'ipfs pin ls -type=recursive' is correct" '
echo "$MBLOCKHASH" >rp_expected &&
echo "$HASH_WELCOME_DOCS" >>rp_expected &&
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>rp_expected &&
ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
sort rp_expected >rp_exp_sorted &&
ipfs pin ls -type=recursive >rp_actual &&