|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Copyright (c) 2014 Christian Couder |
| 4 | +# MIT Licensed; see the LICENSE file in this repository. |
| 5 | +# |
| 6 | + |
| 7 | +test_description="Test init command" |
| 8 | + |
| 9 | +. lib/test-lib.sh |
| 10 | + |
| 11 | +# test that ipfs fails to init if IPFS_PATH isnt writeable |
| 12 | +test_expect_success "create dir and change perms succeeds" ' |
| 13 | + export IPFS_PATH="$(pwd)/.badipfs" && |
| 14 | + mkdir "$IPFS_PATH" && |
| 15 | + chmod 000 "$IPFS_PATH" |
| 16 | +' |
| 17 | + |
| 18 | +test_expect_success "ipfs init fails" ' |
| 19 | + test_must_fail ipfs init 2> init_fail_out |
| 20 | +' |
| 21 | + |
| 22 | +# Under Windows/Cygwin the error message is different, |
| 23 | +# so we use the STD_ERR_MSG prereq. |
| 24 | +if test_have_prereq STD_ERR_MSG; then |
| 25 | + init_err_msg="Error: failed to take lock at $IPFS_PATH: permission denied" |
| 26 | +else |
| 27 | + init_err_msg="Error: mkdir $IPFS_PATH: The system cannot find the path specified." |
| 28 | +fi |
| 29 | +init_js_err_msg="Error: EACCES: permission denied, stat '$IPFS_PATH/version'" |
| 30 | + |
| 31 | +test_expect_success "ipfs init output looks good" ' |
| 32 | + echo "$init_js_err_msg" >init_fail_exp && |
| 33 | + test_cmp init_fail_exp init_fail_out |
| 34 | +' |
| 35 | + |
| 36 | +test_expect_success "cleanup dir with bad perms" ' |
| 37 | + chmod 775 "$IPFS_PATH" && |
| 38 | + rmdir "$IPFS_PATH" |
| 39 | +' |
| 40 | + |
| 41 | +# test no repo error message |
| 42 | +# this applies to `ipfs add sth`, `ipfs refs <hash>` |
| 43 | +test_expect_success "ipfs cat fails" ' |
| 44 | + export IPFS_PATH="$(pwd)/.ipfs" && |
| 45 | + test_must_fail ipfs cat Qmaa4Rw81a3a1VEx4LxB7HADUAXvZFhCoRdBzsMZyZmqHD 2> cat_fail_out |
| 46 | +' |
| 47 | + |
| 48 | +test_done |
0 commit comments