@cryptotaxi247 / kubo / commits / 0ae9b2b90

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.

Andrew Gillis committed Apr 15, 2021 at 11:47 UTC 0ae9b2b9034a57e02df419fe72f705f5a5b3b9c7
1 file changed +45 -10
test/sharness/t0066-migration.sh
+45 -10
@@ -10,16 +10,47 @@ test_description="Test migrations auto update prompt"
10
11 test_init_ipfs
12
13 +MIGRATION_START=7
14 +IPFS_REPO_VER=$(<.ipfs/version)
15 +
16 +# Generate mock migration binaries
17 +gen_mock_migrations() {
18 + mkdir bin
19 + i=$((MIGRATION_START))
20 + until [ $i -ge $IPFS_REPO_VER ]
21 + do
22 + j=$((i+1))
23 + echo "#!/bin/bash" > bin/fs-repo-${i}-to-${j}
24 + echo "echo fake applying ${i}-to-${j} repo migration" >> bin/fs-repo-${i}-to-${j}
25 + chmod +x bin/fs-repo-${i}-to-${j}
26 + ((i++))
27 + done
28 +}
29 +
30 +# Check for expected output from each migration
31 +check_migration_output() {
32 + out_file="$1"
33 + i=$((MIGRATION_START))
34 + until [ $i -ge $IPFS_REPO_VER ]
35 + do
36 + j=$((i+1))
37 + grep "applying ${i}-to-${j} repo migration" "$out_file" > /dev/null
38 + ((i++))
39 + done
40 +}
41 +
42 +# Create fake migration binaries instead of letting ipfs download from network
43 +# To test downloading and running actual binaries, comment out this test.
44 test_expect_success "setup mock migrations" '
14 - mkdir bin &&
15 - echo "#!/bin/bash" > bin/fs-repo-migrations &&
16 - echo "echo 5" >> bin/fs-repo-migrations &&
17 - chmod +x bin/fs-repo-migrations &&
18 - export PATH="$(pwd)/bin":$PATH
45 + gen_mock_migrations &&
46 + find bin -name "fs-repo-*-to-*" | wc -l > mock_count &&
47 + echo $((IPFS_REPO_VER-MIGRATION_START)) > expect_mock_count &&
48 + export PATH="$(pwd)/bin":$PATH &&
49 + test_cmp mock_count expect_mock_count
50 '
51
21 -test_expect_success "manually reset repo version to 3" '
22 - echo "3" > "$IPFS_PATH"/version
52 +test_expect_success "manually reset repo version to $MIGRATION_START" '
53 + echo "$MIGRATION_START" > "$IPFS_PATH"/version
54 '
55
56 test_expect_success "ipfs daemon --migrate=false fails" '
@@ -30,13 +61,17 @@ test_expect_success "output looks good" '
61 grep "Please get fs-repo-migrations from https://dist.ipfs.io" false_out
62 '
63
64 +# The migrations will succeed, but the daemon will still exit with 1 because
65 +# the fake migrations do not update the repo version number.
66 +#
67 +# If run with real migrations, the daemon continues running and must be killed.
68 test_expect_success "ipfs daemon --migrate=true runs migration" '
69 test_expect_code 1 ipfs daemon --migrate=true > true_out
70 '
71
37 -test_expect_failure "output looks good" '
38 - grep "Running: " true_out > /dev/null &&
39 - grep "Success: fs-repo has been migrated to version 5." true_out > /dev/null
72 +test_expect_success "output looks good" '
73 + check_migration_output true_out &&
74 + grep "Success: fs-repo migrated to version $IPFS_REPO_VER" true_out > /dev/null
75 '
76
77 test_expect_success "'ipfs daemon' prompts to auto migrate" '