Skip to content

Commit b9fedf9

Browse files
committed
add a test for repo verify, and make it return non-zero code on failure
License: MIT Signed-off-by: Jeromy <[email protected]>
1 parent 8a9f4af commit b9fedf9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

core/commands/repo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"os"
88
"path/filepath"
9+
"strings"
910

1011
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
1112
cmds "github.com/ipfs/go-ipfs/commands"
@@ -263,6 +264,8 @@ var repoVerifyCmd = &cmds.Command{
263264
}
264265
if fails == 0 {
265266
out <- &VerifyProgress{Message: "verify complete, all blocks validated."}
267+
} else {
268+
out <- &VerifyProgress{Message: "verify complete, some blocks were corrupt."}
266269
}
267270
}()
268271

@@ -280,6 +283,9 @@ var repoVerifyCmd = &cmds.Command{
280283

281284
buf := new(bytes.Buffer)
282285
if obj.Message != "" {
286+
if strings.Contains(obj.Message, "blocks were corrupt") {
287+
return nil, fmt.Errorf(obj.Message)
288+
}
283289
if len(obj.Message) < 20 {
284290
obj.Message += " "
285291
}

test/sharness/t0084-repo-read-rehash.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ test_expect_success 'getting modified block fails' '
3434
grep "block in storage has different hash than requested" err_msg
3535
'
3636

37+
test_expect_success "block shows up in repo verify" '
38+
test_expect_code 1 ipfs repo verify > verify_out &&
39+
grep "$H_BLOCK2" verify_out
40+
'
41+
3742
test_done

0 commit comments

Comments
 (0)