From 0ae9b2b9034a57e02df419fe72f705f5a5b3b9c7 Mon Sep 17 00:00:00 2001 From: Andrew Gillis Date: Thu, 15 Apr 2021 11:47:11 -0700 Subject: [PATCH] Update migration sharness tests for new migrations (#8053) * 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. --- test/sharness/t0066-migration.sh | 55 ++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/test/sharness/t0066-migration.sh b/test/sharness/t0066-migration.sh index 5e1301befb7..aa40fd8a468 100755 --- a/test/sharness/t0066-migration.sh +++ b/test/sharness/t0066-migration.sh @@ -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" ' @@ -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" '