Skip to content

Commit

Permalink
Update migration sharness tests for new migrations (#8053)
Browse files Browse the repository at this point in the history
* Update migration sharness tests for new migrations

With the new migrations, go-ipfs no longer uses fs-repo-migrations to do repo migrations, and was downloading real migration binaries from the network and running them.  This caused failure, but was not caught because the test was expecting `ipfs daemon --migrate` to fail for other reasons.

This PR fixes the migration tests by creating the appropriate fake migration binaries in the PATH so that those get run and avoid downloading the real ones.  This also fixes a test that was previously marked broken.
  • Loading branch information
gammazero authored Apr 15, 2021
1 parent 2693565 commit 0ae9b2b
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions test/sharness/t0066-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,47 @@ test_description="Test migrations auto update prompt"

test_init_ipfs

MIGRATION_START=7
IPFS_REPO_VER=$(<.ipfs/version)

# Generate mock migration binaries
gen_mock_migrations() {
mkdir bin
i=$((MIGRATION_START))
until [ $i -ge $IPFS_REPO_VER ]
do
j=$((i+1))
echo "#!/bin/bash" > bin/fs-repo-${i}-to-${j}
echo "echo fake applying ${i}-to-${j} repo migration" >> bin/fs-repo-${i}-to-${j}
chmod +x bin/fs-repo-${i}-to-${j}
((i++))
done
}

# Check for expected output from each migration
check_migration_output() {
out_file="$1"
i=$((MIGRATION_START))
until [ $i -ge $IPFS_REPO_VER ]
do
j=$((i+1))
grep "applying ${i}-to-${j} repo migration" "$out_file" > /dev/null
((i++))
done
}

# Create fake migration binaries instead of letting ipfs download from network
# To test downloading and running actual binaries, comment out this test.
test_expect_success "setup mock migrations" '
mkdir bin &&
echo "#!/bin/bash" > bin/fs-repo-migrations &&
echo "echo 5" >> bin/fs-repo-migrations &&
chmod +x bin/fs-repo-migrations &&
export PATH="$(pwd)/bin":$PATH
gen_mock_migrations &&
find bin -name "fs-repo-*-to-*" | wc -l > mock_count &&
echo $((IPFS_REPO_VER-MIGRATION_START)) > expect_mock_count &&
export PATH="$(pwd)/bin":$PATH &&
test_cmp mock_count expect_mock_count
'

test_expect_success "manually reset repo version to 3" '
echo "3" > "$IPFS_PATH"/version
test_expect_success "manually reset repo version to $MIGRATION_START" '
echo "$MIGRATION_START" > "$IPFS_PATH"/version
'

test_expect_success "ipfs daemon --migrate=false fails" '
Expand All @@ -30,13 +61,17 @@ test_expect_success "output looks good" '
grep "Please get fs-repo-migrations from https://dist.ipfs.io" false_out
'

# The migrations will succeed, but the daemon will still exit with 1 because
# the fake migrations do not update the repo version number.
#
# If run with real migrations, the daemon continues running and must be killed.
test_expect_success "ipfs daemon --migrate=true runs migration" '
test_expect_code 1 ipfs daemon --migrate=true > true_out
'

test_expect_failure "output looks good" '
grep "Running: " true_out > /dev/null &&
grep "Success: fs-repo has been migrated to version 5." true_out > /dev/null
test_expect_success "output looks good" '
check_migration_output true_out &&
grep "Success: fs-repo migrated to version $IPFS_REPO_VER" true_out > /dev/null
'

test_expect_success "'ipfs daemon' prompts to auto migrate" '
Expand Down

0 comments on commit 0ae9b2b

Please sign in to comment.