Skip to content

Commit

Permalink
Add test for ipfs add err for unsupported file type
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <[email protected]>
  • Loading branch information
rht committed Sep 4, 2015
1 parent ccc9cd6 commit 1b26ca7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/sharness/lib/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,17 @@ disk_usage() {
esac
$DU "$1" | awk "{print \$1}"
}

# output a file's permission in human readable format
generic_stat() {
# normalize stat across systems
case $(uname -s) in
Linux)
_STAT="stat -c %A"
;;
FreeBSD | Darwin | DragonFly)
_STAT="stat -f %Sp"
;;
esac
$_STAT "$1"
}
19 changes: 19 additions & 0 deletions test/sharness/t0040-add-and-cat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ test_description="Test add and cat commands"

. lib/test-lib.sh

client_err() {
printf "$@\n\nUse 'ipfs add --help' for information about this command\n"
}

test_launch_ipfs_daemon_and_mount

test_expect_success "'ipfs add --help' succeeds" '
Expand Down Expand Up @@ -262,6 +266,21 @@ test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
test_cmp sha1_expected sha1_actual
'

test_expect_success "useful error message when adding a named pipe" '
mkfifo named-pipe &&
test_expect_code 1 ipfs add named-pipe 2>actual &&
client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
test_cmp expected actual
'

test_expect_success "useful error message when recursively adding a named pipe" '
mkdir named-pipe-dir &&
mkfifo named-pipe-dir/named-pipe &&
test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
printf "Error: Post http://127.0.0.1:$PORT_API/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true: Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
test_cmp expected actual
'

test_kill_ipfs_daemon

test_done
19 changes: 19 additions & 0 deletions test/sharness/t0041-add-cat-offline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ test_description="Test add and cat commands"

. lib/test-lib.sh

client_err() {
printf "$@\n\nUse 'ipfs add --help' for information about this command\n"
}

test_init_ipfs

test_expect_success "ipfs add file succeeds" '
Expand Down Expand Up @@ -53,4 +57,19 @@ test_expect_success "ipfs cat file fails" '
test_must_fail ipfs cat $(cat oh_hash)
'

test_expect_success "useful error message when adding a named pipe" '
mkfifo named-pipe &&
test_expect_code 1 ipfs add named-pipe 2>actual &&
client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
test_cmp expected actual
'

test_expect_success "useful error message when recursively adding a named pipe" '
mkdir named-pipe-dir &&
mkfifo named-pipe-dir/named-pipe &&
test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
printf "Error: Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
test_cmp expected actual
'

test_done

0 comments on commit 1b26ca7

Please sign in to comment.