Skip to content

Commit ecc5c09

Browse files
committed
Merge pull request #30 from ipfs/test-repo-version
Test repo version
2 parents 3a37320 + 79942ee commit ecc5c09

File tree

2 files changed

+137
-1
lines changed

2 files changed

+137
-1
lines changed

sharness/lib/test-lib.sh

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ GUEST_RANDOM_FILES="sharness/bin/random-files"
8989
test_install_version() {
9090
VERSION="$1"
9191

92+
# We have to change the PATH as ipfs-update might call fs-repo-migrations
9293
test_expect_success "'ipfs-update install' works for $VERSION" '
93-
exec_docker "$DOCID" "PATH=sharness/bin:$PATH; $GUEST_IPFS_UPDATE --verbose install $VERSION" >actual 2>&1 ||
94+
DOCPWD=$(exec_docker "$DOCID" "pwd") &&
95+
DOCPATH=$(exec_docker "$DOCID" "echo \$PATH") &&
96+
NEWPATH="$DOCPWD/sharness/bin:$DOCPATH" &&
97+
exec_docker "$DOCID" "export PATH=\"$NEWPATH\" && $GUEST_IPFS_UPDATE --verbose install $VERSION" >actual 2>&1 ||
9498
test_fsh cat actual
9599
'
96100

@@ -140,3 +144,87 @@ test_init_daemon() {
140144
exec_docker "$docid" "ipfs config Bootstrap --json null"
141145
'
142146
}
147+
148+
test_docker_wait_for_file() {
149+
docid="$1"
150+
loops="$2"
151+
delay="$3"
152+
file="$4"
153+
fwaitc=0
154+
while ! exec_docker "$docid" "test -f '$file'"
155+
do
156+
if test $fwaitc -ge $loops
157+
then
158+
echo "Error: timed out waiting for file: $file"
159+
return 1
160+
fi
161+
162+
go-sleep $delay
163+
fwaitc=$(expr $fwaitc + 1)
164+
done
165+
}
166+
167+
major_number() {
168+
vers="$1"
169+
170+
# Hack around 'expr' exiting with code 1 when it outputs 0
171+
case "$vers" in
172+
0) echo "0" ;;
173+
0.*) echo "0" ;;
174+
*) expr "$vers" : "\([^.]*\).*" || return 1
175+
esac
176+
}
177+
178+
check_at_least_version() {
179+
MIN_VERS="$1"
180+
CUR_VERS="$2"
181+
PROG_NAME="$3"
182+
183+
# Get major, minor and fix numbers for each version
184+
MIN_MAJ=$(major_number "$MIN_VERS") || die "No major version number in '$MIN_VERS' for '$PROG_NAME'"
185+
CUR_MAJ=$(major_number "$CUR_VERS") || die "No major version number in '$CUR_VERS' for '$PROG_NAME'"
186+
187+
if MIN_MIN=$(expr "$MIN_VERS" : "[^.]*\.\([^.]*\).*"); then
188+
MIN_FIX=$(expr "$MIN_VERS" : "[^.]*\.[^.]*\.\([^.]*\).*") || MIN_FIX="0"
189+
else
190+
MIN_MIN="0"
191+
MIN_FIX="0"
192+
fi
193+
if CUR_MIN=$(expr "$CUR_VERS" : "[^.]*\.\([^.]*\).*"); then
194+
CUR_FIX=$(expr "$CUR_VERS" : "[^.]*\.[^.]*\.\([^.]*\).*") || CUR_FIX="0"
195+
else
196+
CUR_MIN="0"
197+
CUR_FIX="0"
198+
fi
199+
200+
# Compare versions
201+
test "$CUR_MAJ" -lt "$MIN_MAJ" && return 1
202+
test "$CUR_MAJ" -gt "$MIN_MAJ" && return 0
203+
test "$CUR_MIN" -lt "$MIN_MIN" && return 1
204+
test "$CUR_MIN" -gt "$MIN_MIN" && return 0
205+
test "$CUR_FIX" -ge "$MIN_FIX"
206+
}
207+
208+
# Print the repo version corresponding to an IPFS_VERSION passed as
209+
# argument.
210+
test_get_repo_version() {
211+
IPFS_VERSION="$1"
212+
213+
REPO_VERSION=1
214+
215+
check_at_least_version "0.3.0" "$IPFS_VERSION" "ipfs" && REPO_VERSION=2
216+
217+
check_at_least_version "0.4.0" "$IPFS_VERSION" "ipfs" && REPO_VERSION=3
218+
219+
echo "$REPO_VERSION"
220+
}
221+
222+
test_repo_version() {
223+
IPFS_VERSION="$1"
224+
225+
test_expect_success "repository version looks good" '
226+
test_get_repo_version "$IPFS_VERSION" >expected &&
227+
exec_docker "$DOCID" "cat \"$IPFS_PATH/version\"" >actual &&
228+
test_cmp expected actual
229+
'
230+
}

sharness/t0070-migration-many.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
test_description="Migration to many different versions"
4+
5+
. lib/test-lib.sh
6+
7+
test_expect_success "start a docker container" '
8+
DOCID=$(start_docker)
9+
'
10+
11+
test_install_version "v0.3.7"
12+
13+
test_expect_success "'ipfs init' succeeds" '
14+
export IPFS_PATH=/root/.ipfs &&
15+
exec_docker "$DOCID" "IPFS_PATH=$IPFS_PATH BITS=2048 ipfs init" >actual 2>&1 ||
16+
test_fsh cat actual
17+
'
18+
19+
test_expect_success ".ipfs/ has been created" '
20+
exec_docker "$DOCID" "test -d /root/.ipfs && test -f /root/.ipfs/config"
21+
exec_docker "$DOCID" "test -d /root/.ipfs/datastore && test -d /root/.ipfs/blocks"
22+
'
23+
24+
test_repo_version "0.3.7"
25+
26+
test_install_version "v0.3.10"
27+
test_repo_version "0.3.10"
28+
29+
test_install_version "v0.4.0-dev"
30+
test_repo_version "0.4.0"
31+
32+
test_install_version "v0.3.8"
33+
34+
# By design reverting a migration has to be run manually
35+
test_expect_success "'ipfs-2-to-3 -revert' succeeds" '
36+
exec_docker "$DOCID" "$GUEST_IPFS_2_TO_3 -revert -path=/root/.ipfs" >actual
37+
'
38+
39+
test_repo_version "0.3.8"
40+
41+
test_install_version "v0.3.10"
42+
test_repo_version "0.3.10"
43+
44+
test_expect_success "stop docker container" '
45+
stop_docker "$DOCID"
46+
'
47+
48+
test_done

0 commit comments

Comments
 (0)