| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2014 Christian Couder |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Test add and cat commands" |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | test_add_skip() { |
| 12 | |
| 13 | test_expect_success "'ipfs add -r' with hidden file succeeds" ' |
| 14 | mkdir -p mountdir/planets/.asteroids && |
| 15 | echo "mars.txt" >mountdir/planets/.gitignore && |
| 16 | echo "Hello Mars" >mountdir/planets/mars.txt && |
| 17 | echo "Hello Venus" >mountdir/planets/venus.txt && |
| 18 | echo "Hello Pluto" >mountdir/planets/.pluto.txt && |
| 19 | echo "Hello Charon" >mountdir/planets/.charon.txt && |
| 20 | echo "Hello Ceres" >mountdir/planets/.asteroids/ceres.txt && |
| 21 | echo "Hello Pallas" >mountdir/planets/.asteroids/pallas.txt && |
| 22 | ipfs add -r mountdir/planets >actual |
| 23 | ' |
| 24 | |
| 25 | test_expect_success "'ipfs add -r' did not include . files" ' |
| 26 | cat >expected <<-\EOF && |
| 27 | added QmZy3khu7qf696i5HtkgL2NotsCZ8wzvNZJ1eUdA5n8KaV planets/mars.txt |
| 28 | added QmQnv4m3Q5512zgVtpbJ9z85osQrzZzGRn934AGh6iVEXz planets/venus.txt |
| 29 | added QmR8nD1Vzk5twWVC6oShTHvv7mMYkVh6dApCByBJyV2oj3 planets |
| 30 | EOF |
| 31 | test_cmp expected actual |
| 32 | ' |
| 33 | |
| 34 | test_expect_success "'ipfs add -r --hidden' succeeds" ' |
| 35 | ipfs add -r --hidden mountdir/planets >actual |
| 36 | ' |
| 37 | |
| 38 | test_expect_success "'ipfs add -r --hidden' did include . files" ' |
| 39 | cat >expected <<-\EOF && |
| 40 | added QmcAREBcjgnUpKfyFmUGnfajA1NQS5ydqRp7WfqZ6JF8Dx planets/.asteroids/ceres.txt |
| 41 | added QmZ5eaLybJ5GUZBNwy24AA9EEDTDpA4B8qXnuN3cGxu2uF planets/.asteroids/pallas.txt |
| 42 | added QmaowqjedBkUrMUXgzt9c2ZnAJncM9jpJtkFfgdFstGr5a planets/.charon.txt |
| 43 | added QmPHrRjTH8FskN3C2iv6BLekDT94o23KSL2u5qLqQqGhVH planets/.gitignore |
| 44 | added QmU4zFD5eJtRBsWC63AvpozM9Atiadg9kPVTuTrnCYJiNF planets/.pluto.txt |
| 45 | added QmZy3khu7qf696i5HtkgL2NotsCZ8wzvNZJ1eUdA5n8KaV planets/mars.txt |
| 46 | added QmQnv4m3Q5512zgVtpbJ9z85osQrzZzGRn934AGh6iVEXz planets/venus.txt |
| 47 | added Qmf6rbs5GF85anDuoxpSAdtuZPM9D2Yt3HngzjUVSQ7kDV planets/.asteroids |
| 48 | added QmczhHaXyb3bc9APMxe4MXbr87V5YDLKLaw3DZX3fK7HrK planets |
| 49 | EOF |
| 50 | test_cmp expected actual |
| 51 | ' |
| 52 | |
| 53 | test_expect_success "'ipfs add -r --ignore-rules-path=.gitignore --hidden' succeeds" ' |
| 54 | (cd mountdir/planets && ipfs add -r --ignore-rules-path=.gitignore --hidden .) > actual |
| 55 | ' |
| 56 | |
| 57 | test_expect_success "'ipfs add -r --ignore-rules-path=.gitignore --hidden' did not include mars.txt file" ' |
| 58 | cat >expected <<-\EOF && |
| 59 | added QmcAREBcjgnUpKfyFmUGnfajA1NQS5ydqRp7WfqZ6JF8Dx planets/.asteroids/ceres.txt |
| 60 | added QmZ5eaLybJ5GUZBNwy24AA9EEDTDpA4B8qXnuN3cGxu2uF planets/.asteroids/pallas.txt |
| 61 | added QmaowqjedBkUrMUXgzt9c2ZnAJncM9jpJtkFfgdFstGr5a planets/.charon.txt |
| 62 | added QmPHrRjTH8FskN3C2iv6BLekDT94o23KSL2u5qLqQqGhVH planets/.gitignore |
| 63 | added QmU4zFD5eJtRBsWC63AvpozM9Atiadg9kPVTuTrnCYJiNF planets/.pluto.txt |
| 64 | added QmQnv4m3Q5512zgVtpbJ9z85osQrzZzGRn934AGh6iVEXz planets/venus.txt |
| 65 | added Qmf6rbs5GF85anDuoxpSAdtuZPM9D2Yt3HngzjUVSQ7kDV planets/.asteroids |
| 66 | added QmaRsiaCYvc65RqHVAcv2tqyjZgQYgvaNqW1tQGsjfy4N5 planets |
| 67 | EOF |
| 68 | test_cmp expected actual |
| 69 | ' |
| 70 | |
| 71 | test_expect_success "'ipfs add -r --ignore-rules-path=.gitignore --ignore .asteroids --ignore venus.txt --hidden' succeeds" ' |
| 72 | (cd mountdir/planets && ipfs add -r --ignore-rules-path=.gitignore --ignore .asteroids --ignore venus.txt --hidden .) > actual |
| 73 | ' |
| 74 | |
| 75 | test_expect_success "'ipfs add -r --ignore-rules-path=.gitignore --ignore .asteroids --ignore venus.txt --hidden' did not include ignored files" ' |
| 76 | cat >expected <<-\EOF && |
| 77 | added QmaowqjedBkUrMUXgzt9c2ZnAJncM9jpJtkFfgdFstGr5a planets/.charon.txt |
| 78 | added QmPHrRjTH8FskN3C2iv6BLekDT94o23KSL2u5qLqQqGhVH planets/.gitignore |
| 79 | added QmU4zFD5eJtRBsWC63AvpozM9Atiadg9kPVTuTrnCYJiNF planets/.pluto.txt |
| 80 | added QmemuMahjSh7eYLY3hbz2q8sqMPnbQzBQeUdosqNiWChE6 planets |
| 81 | EOF |
| 82 | test_cmp expected actual |
| 83 | ' |
| 84 | |
| 85 | test_expect_success "'ipfs add' includes hidden files given explicitly even without --hidden" ' |
| 86 | mkdir -p mountdir/dotfiles && |
| 87 | echo "set nocompatible" > mountdir/dotfiles/.vimrc |
| 88 | cat >expected <<-\EOF && |
| 89 | added QmT4uMRDCN7EMpFeqwvKkboszbqeW1kWVGrBxBuCGqZcQc .vimrc |
| 90 | EOF |
| 91 | ipfs add mountdir/dotfiles/.vimrc >actual |
| 92 | cat actual |
| 93 | test_cmp expected actual |
| 94 | ' |
| 95 | |
| 96 | test_expect_success "'ipfs add' with an unregistered hash and wrapped leaves fails without crashing" ' |
| 97 | test_expect_code 1 ipfs add --hash poseidon-bls12_381-a2-fc1 --raw-leaves=false -r mountdir/planets |
| 98 | ' |
| 99 | |
| 100 | } |
| 101 | |
| 102 | # should work offline |
| 103 | test_init_ipfs |
| 104 | test_add_skip |
| 105 | |
| 106 | # should work online |
| 107 | test_launch_ipfs_daemon |
| 108 | test_add_skip |
| 109 | test_kill_ipfs_daemon |
| 110 | |
| 111 | test_done |