Skip to content

Commit

Permalink
files api: redo tests
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Jun 23, 2017
1 parent f936b1c commit 6586737
Showing 1 changed file with 28 additions and 54 deletions.
82 changes: 28 additions & 54 deletions test/sharness/t0250-files-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ test_description="test the unix files api"

test_init_ipfs

# setup files for testing
test_expect_success "can create some files for testing" '
FILE1=$(echo foo | ipfs add -q) &&
FILE2=$(echo bar | ipfs add -q) &&
FILE3=$(echo baz | ipfs add -q) &&
FILE9=$(echo zip | ipfs add -q --raw-leaves) &&
mkdir stuff_test &&
create_files() {
add_args=( "$@" )
FILE1=$(echo foo | ipfs add ${add_args[@]} -q) &&
FILE2=$(echo bar | ipfs add ${add_args[@]} -q) &&
FILE3=$(echo baz | ipfs add ${add_args[@]} -q) &&
mkdir -f stuff_test &&
echo cats > stuff_test/a &&
echo dogs > stuff_test/b &&
echo giraffes > stuff_test/c &&
DIR1=$(ipfs add -q stuff_test | tail -n1)
DIR1=$(ipfs add -r ${add_args[@]} -q stuff_test | tail -n1)
}

# setup files for testing
test_expect_success "can create some files for testing" '
create_files
'

verify_path_exists() {
Expand Down Expand Up @@ -73,16 +77,6 @@ test_sharding() {
test_cmp file_out file_exp
'

test_expect_success "can pin a file from sharded directory" '
ipfs files stat --hash /foo/file42 > pin_file_hash &&
ipfs pin add < pin_file_hash > pin_hash
'

test_expect_success "can unpin a file from sharded directory" '
read -r _ HASH _ < pin_hash &&
ipfs pin rm $HASH
'

test_expect_success "output object was really sharded" '
ipfs files stat --hash /foo > expected_foo_hash &&
echo QmPkwLJTYZRGPJ8Lazr9qPdrLmswPtUjaDbEpmR9jEh1se > actual_foo_hash &&
Expand Down Expand Up @@ -253,42 +247,6 @@ test_files_api() {
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_expect_success "read from offset works" '
Expand Down Expand Up @@ -581,4 +539,20 @@ test_launch_ipfs_daemon
test_sharding
test_kill_ipfs_daemon


test_expect_success "enable sharding in config" '
ipfs config --json Experimental.ShardingEnabled false
'


test_launch_ipfs_daemon

test_expect_success "can create some files for testing with raw-leaves" '
create_files --raw-leaves
'

test_files_api

test_kill_ipfs_daemon

test_done

0 comments on commit 6586737

Please sign in to comment.