1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 19:44:01 +08:00

updates from PR, tests tests tests!

This commit is contained in:
Jeromy
2015-01-21 08:50:33 +00:00
parent 4de881a185
commit 8e7d984751
4 changed files with 76 additions and 24 deletions

View File

@ -42,11 +42,19 @@ order to reclaim hard disk space.
return nil, err
}
outChan, err := corerepo.GarbageCollectBlockstore(n, req.Context().Context)
gcOutChan, err := corerepo.GarbageCollectBlockstore(n, req.Context().Context)
if err != nil {
return nil, err
}
outChan := make(chan interface{})
go func() {
defer close(outChan)
for k := range gcOutChan {
outChan <- k
}
}()
return outChan, nil
},
Type: corerepo.KeyRemoved{},

View File

@ -81,7 +81,7 @@ var rootSubcommands = map[string]*cmds.Command{
"pin": PinCmd,
"ping": PingCmd,
"refs": RefsCmd,
"repo": RepoCmd,
"repo": RepoCmd,
"swarm": SwarmCmd,
"update": UpdateCmd,
"version": VersionCmd,

View File

@ -14,14 +14,14 @@ type KeyRemoved struct {
Key u.Key
}
func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan interface{}, error) {
func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan *KeyRemoved, error) {
keychan, err := n.Blockstore.AllKeysChan(ctx, 0, 1<<16)
if err != nil {
return nil, err
}
output := make(chan interface{})
output := make(chan *KeyRemoved)
go func() {
defer close(output)
for {
@ -34,6 +34,7 @@ func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan int
err := n.Blockstore.DeleteBlock(k)
if err != nil {
log.Errorf("Error removing key from blockstore: %s", err)
continue
}
select {
case output <- &KeyRemoved{k}:

View File

@ -18,68 +18,111 @@ test_expect_success "'ipfs add afile' succeeds" '
'
test_expect_success "added file was pinned" '
ipfs pin ls -type=recursive | grep `cat hashfile`
ipfs pin ls -type=recursive | grep $HASH
'
test_expect_success "'ipfs repo gc' doesnt remove file" '
ipfs repo gc
ipfs cat `cat hashfile` > out
echo -n "" > empty
ipfs repo gc > gc_out_actual
test_cmp empty gc_out_actual
ipfs cat $HASH > out
test_cmp out afile
'
test_expect_success "'ipfs pin rm' succeeds" '
echo unpinned `cat hashfile` > expected1
ipfs pin rm -r `cat hashfile` > actual1
echo unpinned $HASH > expected1
ipfs pin rm -r $HASH > actual1
test_cmp expected1 actual1
'
test_expect_success "file no longer pinned" '
echo -n "" > expected2
ipfs pin ls -type=recursive > actual2
test_cmp expected2 actual2
test_cmp empty actual2
'
test_expect_success "recursively pin afile" '
ipfs pin add -r `cat hashfile`
ipfs pin add -r $HASH
'
test_expect_success "pinning directly should fail now" '
echo Error: pin: `cat hashfile` already pinned recursively > expected3
ipfs pin add `cat hashfile` 2> actual3
echo Error: pin: $HASH already pinned recursively > expected3
ipfs pin add $HASH 2> actual3
test_cmp expected3 actual3
'
test_expect_success "'ipfs pin rm <hash>' should fail" '
echo Error: `cat hashfile` is pinned recursively > expected4
ipfs pin rm `cat hashfile` 2> actual4
echo Error: $HASH is pinned recursively > expected4
ipfs pin rm $HASH 2> actual4
test_cmp expected4 actual4
'
test_expect_success "remove recursive pin, add direct" '
echo unpinned `cat hashfile` > expected5
ipfs pin rm -r `cat hashfile` > actual5
echo unpinned $HASH > expected5
ipfs pin rm -r $HASH > actual5
test_cmp expected5 actual5
ipfs pin add `cat hashfile`
ipfs pin add $HASH
'
test_expect_success "remove direct pin" '
echo unpinned `cat hashfile` > expected6
ipfs pin rm `cat hashfile` > actual6
echo unpinned $HASH > expected6
ipfs pin rm $HASH > actual6
test_cmp expected6 actual6
'
test_expect_success "'ipfs repo gc' removes file" '
echo removed `cat hashfile` > expected7
echo removed $HASH > expected7
ipfs repo gc > actual7
test_cmp expected7 actual7
'
test_expect_success "'ipfs refs local' no longer shows file" '
echo -n "" > expected8
ipfs refs local > actual8
test_cmp expected8 actual8
test_cmp empty actual8
'
test_expect_success "adding multiblock random file succeeds" '
random 1000000 > multiblock
MBLOCKHASH=`ipfs add -q multiblock`
'
test_expect_success "'ipfs pin ls -type=indirect' is correct" '
ipfs refs $MBLOCKHASH | sort > refsout
ipfs pin ls -type=indirect | sort > indirectpins
test_cmp refsout indirectpins
'
test_expect_success "pin something directly" '
echo "ipfs is so awesome" > awesome
DIRECTPIN=`ipfs add -q awesome`
echo unpinned $DIRECTPIN > expected9
ipfs pin rm -r $DIRECTPIN > actual9
test_cmp expected9 actual9
echo pinned $DIRECTPIN directly > expected10
ipfs pin add $DIRECTPIN > actual10
test_cmp expected10 actual10
'
test_expect_success "'ipfs pin ls -type=direct' is correct" '
echo $DIRECTPIN > directpinhash
ipfs pin ls -type=direct > directpinout
test_cmp directpinhash directpinout
'
test_expect_success "'ipfs pin ls -type=recursive' is correct" '
echo $MBLOCKHASH > rp_expected
ipfs pin ls -type=recursive > rp_actual
test_cmp rp_expected rp_actual
'
test_expect_success "'ipfs pin ls -type=all' is correct" '
cat directpinout > allpins
cat rp_actual >> allpins
cat indirectpins >> allpins
cat allpins | sort > allpins_sorted
ipfs pin ls -type=all | sort > actual_allpins
test_cmp allpins_sorted actual_allpins
'
test_kill_ipfs_daemon