t0200-unixfs-ls.sh 6.41 KB
Newer Older
1 2 3 4 5 6
#!/bin/sh
#
# Copyright (c) 2014 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#

7
test_description="Test file ls command"
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

. lib/test-lib.sh

test_init_ipfs

test_ls_cmd() {

	test_expect_success "'ipfs add -r testData' succeeds" '
		mkdir -p testData testData/d1 testData/d2 &&
		echo "test" >testData/f1 &&
		echo "data" >testData/f2 &&
		echo "hello" >testData/d1/a &&
		random 128 42 >testData/d1/128 &&
		echo "world" >testData/d2/a &&
		random 1024 42 >testData/d2/1024 &&
		ipfs add -r testData >actual_add
	'

	test_expect_success "'ipfs add' output looks good" '
		cat <<-\EOF >expected_add &&
			added QmQNd6ubRXaNG6Prov8o6vk3bn6eWsj9FxLGrAVDUAGkGe testData/d1/128
			added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN testData/d1/a
			added QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss testData/d1
			added QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd testData/d2/1024
			added QmaRGe7bVmVaLmxbrMiVNXqW4pRNNp3xq7hFtyRKA3mtJL testData/d2/a
			added QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy testData/d2
			added QmeomffUNfmQy76CQGy9NdmqEnnHU9soCexBnGU3ezPHVH testData/f1
			added QmNtocSs7MoDkJMc1RkyisCSKvLadujPsfJfSdJ3e1eA1M testData/f2
			added QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj testData
		EOF
		test_cmp expected_add actual_add
	'

41 42 43 44 45 46 47 48 49 50 51 52
	test_expect_success "'ipfs file ls <dir>' succeeds" '
		ipfs file ls QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy >actual_ls_one_directory
	'

	test_expect_success "'ipfs file ls <dir>' output looks good" '
		cat <<-\EOF >expected_ls_one_directory &&
			1024
			a
		EOF
		test_cmp expected_ls_one_directory actual_ls_one_directory
	'

53
	test_expect_success "'ipfs file ls <three dir hashes>' succeeds" '
54
		ipfs file ls QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls_three_directories
55 56
	'

57
	test_expect_success "'ipfs file ls <three dir hashes>' output looks good" '
58
		cat <<-\EOF >expected_ls_three_directories &&
59 60 61 62 63 64 65
			QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy:
			1024
			a

			QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss:
			128
			a
66 67 68 69 70 71

			QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj:
			d1
			d2
			f1
			f2
72
		EOF
73
		test_cmp expected_ls_three_directories actual_ls_three_directories
74
	'
75

76 77
	test_expect_success "'ipfs file ls <file hashes>' succeeds" '
		ipfs file ls /ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024 QmQNd6ubRXaNG6Prov8o6vk3bn6eWsj9FxLGrAVDUAGkGe >actual_ls_file
78 79
	'

80
	test_expect_success "'ipfs file ls <file hashes>' output looks good" '
81 82 83 84 85 86
		cat <<-\EOF >expected_ls_file &&
			/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024
			QmQNd6ubRXaNG6Prov8o6vk3bn6eWsj9FxLGrAVDUAGkGe
		EOF
		test_cmp expected_ls_file actual_ls_file
	'
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
	test_expect_success "'ipfs file ls <duplicates>' succeeds" '
		ipfs file ls /ipfs/QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj/d1 /ipfs/QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss /ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024 /ipfs/QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd >actual_ls_duplicates_file
	'

	test_expect_success "'ipfs file ls <duplicates>' output looks good" '
		cat <<-\EOF >expected_ls_duplicates_file &&
			/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024
			/ipfs/QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd

			/ipfs/QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss:
			/ipfs/QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj/d1:
			128
			a
		EOF
		test_cmp expected_ls_duplicates_file actual_ls_duplicates_file
	'

105 106 107 108 109 110 111
	test_expect_success "'ipfs --encoding=json file ls <file hashes>' succeeds" '
		ipfs --encoding=json file ls /ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024 >actual_json_ls_file
	'

	test_expect_success "'ipfs --encoding=json file ls <file hashes>' output looks good" '
		cat <<-\EOF >expected_json_ls_file_trailing_newline &&
			{
112 113 114 115 116
			  "Arguments": {
			    "/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd"
			  },
			  "Objects": {
			    "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd": {
117 118 119 120
			      "Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
			      "Size": 1024,
			      "Type": "File",
			      "Links": null
121
			    }
122
			  }
123 124
			}
		EOF
125
		printf "%s\n" "$(cat expected_json_ls_file_trailing_newline)" >expected_json_ls_file &&
126 127
		test_cmp expected_json_ls_file actual_json_ls_file
	'
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

	test_expect_success "'ipfs --encoding=json file ls <duplicates>' succeeds" '
		ipfs --encoding=json file ls /ipfs/QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj/d1 /ipfs/QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss /ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024 /ipfs/QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd >actual_json_ls_duplicates_file
	'

	test_expect_success "'ipfs --encoding=json file ls <duplicates>' output looks good" '
		cat <<-\EOF >expected_json_ls_duplicates_file_trailing_newline &&
			{
			  "Arguments": {
			    "/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
			    "/ipfs/QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss": "QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss",
			    "/ipfs/QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
			    "/ipfs/QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj/d1": "QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss"
			  },
			  "Objects": {
			    "QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss": {
144 145 146
			      "Hash": "QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss",
			      "Size": 0,
			      "Type": "Directory",
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
			      "Links": [
			        {
			          "Name": "128",
			          "Hash": "QmQNd6ubRXaNG6Prov8o6vk3bn6eWsj9FxLGrAVDUAGkGe",
			          "Size": 128,
			          "Type": "File"
			        },
			        {
			          "Name": "a",
			          "Hash": "QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN",
			          "Size": 6,
			          "Type": "File"
			        }
			      ]
			    },
			    "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd": {
163 164 165 166
			      "Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
			      "Size": 1024,
			      "Type": "File",
			      "Links": null
167 168 169 170
			    }
			  }
			}
		EOF
171
		printf "%s\n" "$(cat expected_json_ls_duplicates_file_trailing_newline)" >expected_json_ls_duplicates_file &&
172 173
		test_cmp expected_json_ls_duplicates_file actual_json_ls_duplicates_file
	'
174 175 176 177 178 179 180 181 182 183 184 185
}


# should work offline
test_ls_cmd

# should work online
test_launch_ipfs_daemon
test_ls_cmd
test_kill_ipfs_daemon

test_done