Add test for ipfs add err for unsupported file type
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Sep 4, 2015 at 16:55 UTC
1b26ca724f9dda116ab959db14e5bafc64bbf51b
3 files changed
+52
test/sharness/lib/test-lib.sh
+14
@@ -330,3 +330,17 @@ disk_usage() {
330
esac
331
$DU "$1" | awk "{print \$1}"
332
}
333
+
334
+# output a file's permission in human readable format
335
+generic_stat() {
336
+ # normalize stat across systems
337
+ case $(uname -s) in
338
+ Linux)
339
+ _STAT="stat -c %A"
340
+ ;;
341
+ FreeBSD | Darwin | DragonFly)
342
+ _STAT="stat -f %Sp"
343
+ ;;
344
+ esac
345
+ $_STAT "$1"
346
+}
test/sharness/t0040-add-and-cat.sh
+19
@@ -8,6 +8,10 @@ test_description="Test add and cat commands"
8
9
. lib/test-lib.sh
10
11
+client_err() {
12
+ printf "$@\n\nUse 'ipfs add --help' for information about this command\n"
13
+}
14
+
15
test_launch_ipfs_daemon_and_mount
16
17
test_expect_success "'ipfs add --help' succeeds" '
@@ -262,6 +266,21 @@ test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
266
test_cmp sha1_expected sha1_actual
267
'
268
269
+test_expect_success "useful error message when adding a named pipe" '
270
+ mkfifo named-pipe &&
271
+ test_expect_code 1 ipfs add named-pipe 2>actual &&
272
+ client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
273
+ test_cmp expected actual
274
+'
275
+
276
+test_expect_success "useful error message when recursively adding a named pipe" '
277
+ mkdir named-pipe-dir &&
278
+ mkfifo named-pipe-dir/named-pipe &&
279
+ test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
280
+ 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 &&
281
+ test_cmp expected actual
282
+'
283
+
284
test_kill_ipfs_daemon
285
286
test_done
test/sharness/t0041-add-cat-offline.sh
+19
@@ -8,6 +8,10 @@ test_description="Test add and cat commands"
8
9
. lib/test-lib.sh
10
11
+client_err() {
12
+ printf "$@\n\nUse 'ipfs add --help' for information about this command\n"
13
+}
14
+
15
test_init_ipfs
16
17
test_expect_success "ipfs add file succeeds" '
@@ -53,4 +57,19 @@ test_expect_success "ipfs cat file fails" '
57
test_must_fail ipfs cat $(cat oh_hash)
58
'
59
60
+test_expect_success "useful error message when adding a named pipe" '
61
+ mkfifo named-pipe &&
62
+ test_expect_code 1 ipfs add named-pipe 2>actual &&
63
+ client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
64
+ test_cmp expected actual
65
+'
66
+
67
+test_expect_success "useful error message when recursively adding a named pipe" '
68
+ mkdir named-pipe-dir &&
69
+ mkfifo named-pipe-dir/named-pipe &&
70
+ test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
71
+ printf "Error: Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
72
+ test_cmp expected actual
73
+'
74
+
75
test_done