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 26, 2017
1 parent 3f6a7b7 commit 33f699f
Showing 1 changed file with 45 additions and 54 deletions.
99 changes: 45 additions & 54 deletions test/sharness/t0250-files-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ 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() {
FILE1=$(echo foo | ipfs add "$@" -q) &&
FILE2=$(echo bar | ipfs add "$@" -q) &&
FILE3=$(echo baz | ipfs add "$@" -q) &&
mkdir -p 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 "$@" -q stuff_test | tail -n1)
}

verify_path_exists() {
# simply running ls on a file should be a good 'check'
Expand Down Expand Up @@ -91,6 +89,8 @@ test_sharding() {
}

test_files_api() {
ROOT_HASH=$1

test_expect_success "can mkdir in root" '
ipfs files mkdir /cats
'
Expand Down Expand Up @@ -160,6 +160,12 @@ test_files_api() {
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" '
ipfs files read /cats/file1 > file1out
'
Expand Down Expand Up @@ -253,42 +259,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 @@ -439,15 +409,15 @@ test_files_api() {
test_expect_success "root hash not bubbled up yet" '
test -z "$ONLINE" ||
(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" '
ipfs files stat --hash / > root_hash
'

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 &&
test_cmp root_hash_exp root_hash
'
Expand Down Expand Up @@ -558,26 +528,47 @@ test_files_api() {
ipfs files rm -r /foobar &&
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_files_api
test_expect_success "can create some files for testing" '
create_files
'
test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt

test_expect_success "clean up objects from previous test run" '
ipfs repo gc
test_expect_success "can create some files for testing with raw-leaves" '
create_files --raw-leaves
'
test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ

test_launch_ipfs_daemon
test_launch_ipfs_daemon --offline

ONLINE=1 # set online flag so tests can easily tell
test_files_api
test_kill_ipfs_daemon
test_expect_success "can create some files for testing" '
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" '
ipfs config --json Experimental.ShardingEnabled true
'

test_launch_ipfs_daemon
test_launch_ipfs_daemon --offline
test_sharding
test_kill_ipfs_daemon

Expand Down

0 comments on commit 33f699f

Please sign in to comment.