| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # MIT Licensed; see the LICENSE file in this repository. |
| 4 | # |
| 5 | |
| 6 | test_description="Test api file" |
| 7 | |
| 8 | . lib/test-lib.sh |
| 9 | |
| 10 | test_init_ipfs |
| 11 | |
| 12 | |
| 13 | test_launch_ipfs_daemon |
| 14 | test_kill_ipfs_daemon |
| 15 | |
| 16 | test_expect_success "version always works" ' |
| 17 | ipfs version >/dev/null |
| 18 | ' |
| 19 | |
| 20 | test_expect_success "swarm peers fails when offline" ' |
| 21 | test_must_fail ipfs swarm peers >/dev/null |
| 22 | ' |
| 23 | |
| 24 | test_expect_success "swarm peers fails when offline and API specified" ' |
| 25 | test_must_fail ipfs swarm peers --api="$API_MADDR" >/dev/null |
| 26 | ' |
| 27 | |
| 28 | test_expect_success "pin ls succeeds when offline" ' |
| 29 | ipfs pin ls >/dev/null |
| 30 | ' |
| 31 | |
| 32 | test_expect_success "pin ls fails when offline and API specified" ' |
| 33 | test_must_fail ipfs pin ls --api="$API_MADDR" >/dev/null |
| 34 | ' |
| 35 | |
| 36 | test_expect_success "id succeeds when offline" ' |
| 37 | ipfs id >/dev/null |
| 38 | ' |
| 39 | |
| 40 | test_expect_success "id fails when offline API specified" ' |
| 41 | test_must_fail ipfs id --api="$API_MADDR" >/dev/null |
| 42 | ' |
| 43 | |
| 44 | test_expect_success "create API file" ' |
| 45 | echo "$API_MADDR" > "$IPFS_PATH/api" |
| 46 | ' |
| 47 | |
| 48 | test_expect_success "version always works" ' |
| 49 | ipfs version >/dev/null |
| 50 | ' |
| 51 | |
| 52 | test_expect_success "id succeeds when offline and API file exists" ' |
| 53 | ipfs id >/dev/null |
| 54 | ' |
| 55 | |
| 56 | test_expect_success "pin ls succeeds when offline and API file exists" ' |
| 57 | ipfs pin ls >/dev/null |
| 58 | ' |
| 59 | |
| 60 | test_launch_ipfs_daemon |
| 61 | |
| 62 | test_expect_success "version always works" ' |
| 63 | ipfs version >/dev/null |
| 64 | ' |
| 65 | |
| 66 | test_expect_success "id succeeds when online" ' |
| 67 | ipfs id >/dev/null |
| 68 | ' |
| 69 | |
| 70 | test_expect_success "swarm peers succeeds when online" ' |
| 71 | ipfs swarm peers >/dev/null |
| 72 | ' |
| 73 | |
| 74 | test_expect_success "pin ls succeeds when online" ' |
| 75 | ipfs pin ls >/dev/null |
| 76 | ' |
| 77 | |
| 78 | test_expect_success "remove API file when daemon is running" ' |
| 79 | rm "$IPFS_PATH/api" |
| 80 | ' |
| 81 | |
| 82 | test_expect_success "version always works" ' |
| 83 | ipfs version >/dev/null |
| 84 | ' |
| 85 | |
| 86 | test_expect_success "swarm peers fails when the API file is missing" ' |
| 87 | test_must_fail ipfs swarm peers >/dev/null |
| 88 | ' |
| 89 | |
| 90 | test_expect_success "id fails when daemon is running but API file is missing (locks repo)" ' |
| 91 | test_must_fail ipfs pin ls >/dev/null |
| 92 | ' |
| 93 | |
| 94 | test_expect_success "pin ls fails when daemon is running but API file is missing (locks repo)" ' |
| 95 | test_must_fail ipfs pin ls >/dev/null |
| 96 | ' |
| 97 | |
| 98 | test_kill_ipfs_daemon |
| 99 | |
| 100 | APIPORT=32563 |
| 101 | |
| 102 | test_expect_success "Verify gateway file diallable while on unspecified" ' |
| 103 | ipfs config Addresses.API /ip4/0.0.0.0/tcp/$APIPORT && |
| 104 | test_launch_ipfs_daemon && |
| 105 | cat "$IPFS_PATH/api" > api_file_actual && |
| 106 | echo -n "/ip4/127.0.0.1/tcp/$APIPORT" > api_file_expected && |
| 107 | test_cmp api_file_expected api_file_actual |
| 108 | ' |
| 109 | |
| 110 | test_kill_ipfs_daemon |
| 111 | |
| 112 | test_done |