1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

files api: redo tests

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
This commit is contained in:
Kevin Atkinson
2017-06-26 02:41:28 -04:00
parent 3f6a7b7b81
commit 33f699f8de

View File

@ -10,18 +10,16 @@ test_description="test the unix files api"
test_init_ipfs test_init_ipfs
# setup files for testing create_files() {
test_expect_success "can create some files for testing" ' FILE1=$(echo foo | ipfs add "$@" -q) &&
FILE1=$(echo foo | ipfs add -q) && FILE2=$(echo bar | ipfs add "$@" -q) &&
FILE2=$(echo bar | ipfs add -q) && FILE3=$(echo baz | ipfs add "$@" -q) &&
FILE3=$(echo baz | ipfs add -q) && mkdir -p stuff_test &&
FILE9=$(echo zip | ipfs add -q --raw-leaves) &&
mkdir stuff_test &&
echo cats > stuff_test/a && echo cats > stuff_test/a &&
echo dogs > stuff_test/b && echo dogs > stuff_test/b &&
echo giraffes > stuff_test/c && echo giraffes > stuff_test/c &&
DIR1=$(ipfs add -q stuff_test | tail -n1) DIR1=$(ipfs add -r "$@" -q stuff_test | tail -n1)
' }
verify_path_exists() { verify_path_exists() {
# simply running ls on a file should be a good 'check' # simply running ls on a file should be a good 'check'
@ -91,6 +89,8 @@ test_sharding() {
} }
test_files_api() { test_files_api() {
ROOT_HASH=$1
test_expect_success "can mkdir in root" ' test_expect_success "can mkdir in root" '
ipfs files mkdir /cats ipfs files mkdir /cats
' '
@ -160,6 +160,12 @@ test_files_api() {
verify_dir_contents /cats file1 verify_dir_contents /cats file1
' '
test_expect_success "file has correct hash and size in directory" '
echo "file1 $FILE1 4" > ls_l_expected &&
ipfs files ls -l /cats > ls_l_actual &&
test_cmp ls_l_expected ls_l_actual
'
test_expect_success "can read file" ' test_expect_success "can read file" '
ipfs files read /cats/file1 > file1out ipfs files read /cats/file1 > file1out
' '
@ -253,42 +259,6 @@ test_files_api() {
test_cmp roothash roothashafter test_cmp roothash roothashafter
' '
# test raw node
test_expect_success "can put a raw-node into root" '
ipfs files cp /ipfs/$FILE9 /file9
'
test_expect_success "file shows up in root" '
verify_dir_contents / file9 cats
'
test_expect_success "can read file" '
ipfs files read /file9 > file9out
'
test_expect_success "output looks good" '
echo zip > expected &&
test_cmp expected file9out
'
test_expect_success "can remove file from root" '
ipfs files rm /file9
'
test_expect_success "file no longer appears" '
verify_dir_contents / cats
'
test_expect_success "check root hash" '
ipfs files stat --hash / > roothash
'
test_expect_success "check root hash was not changed" '
ipfs files stat --hash / > roothashafter &&
test_cmp roothash roothashafter
'
# test read options # test read options
test_expect_success "read from offset works" ' test_expect_success "read from offset works" '
@ -439,7 +409,7 @@ test_files_api() {
test_expect_success "root hash not bubbled up yet" ' test_expect_success "root hash not bubbled up yet" '
test -z "$ONLINE" || test -z "$ONLINE" ||
(ipfs refs local > refsout && (ipfs refs local > refsout &&
test_expect_code 1 grep QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt refsout) test_expect_code 1 grep $ROOT_HASH refsout)
' '
test_expect_success "changes bubbled up to root on inspection" ' test_expect_success "changes bubbled up to root on inspection" '
@ -447,7 +417,7 @@ test_files_api() {
' '
test_expect_success "root hash looks good" ' test_expect_success "root hash looks good" '
export EXP_ROOT_HASH="QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt" && export EXP_ROOT_HASH="$ROOT_HASH" &&
echo $EXP_ROOT_HASH > root_hash_exp && echo $EXP_ROOT_HASH > root_hash_exp &&
test_cmp root_hash_exp root_hash test_cmp root_hash_exp root_hash
' '
@ -558,26 +528,47 @@ test_files_api() {
ipfs files rm -r /foobar && ipfs files rm -r /foobar &&
ipfs files rm -r /adir ipfs files rm -r /adir
' '
test_expect_success "root mfs entry is empyt" '
verify_dir_contents /
'
test_expect_success "repo gc" '
ipfs repo gc
'
} }
# test offline and online # test offline and online
test_files_api test_expect_success "can create some files for testing" '
create_files
test_expect_success "clean up objects from previous test run" '
ipfs repo gc
' '
test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
test_launch_ipfs_daemon test_expect_success "can create some files for testing with raw-leaves" '
create_files --raw-leaves
'
test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
test_launch_ipfs_daemon --offline
ONLINE=1 # set online flag so tests can easily tell ONLINE=1 # set online flag so tests can easily tell
test_files_api test_expect_success "can create some files for testing" '
test_kill_ipfs_daemon create_files
'
test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
test_expect_success "can create some files for testing with raw-leaves" '
create_files --raw-leaves
'
test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
test_kill_ipfs_daemon --offline
test_expect_success "enable sharding in config" ' test_expect_success "enable sharding in config" '
ipfs config --json Experimental.ShardingEnabled true ipfs config --json Experimental.ShardingEnabled true
' '
test_launch_ipfs_daemon test_launch_ipfs_daemon --offline
test_sharding test_sharding
test_kill_ipfs_daemon test_kill_ipfs_daemon