add tests to make sure docker requests correct migrations version
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Feb 16, 2017 at 14:56 UTC
c817f09b8ab49abb80fdced7494d92d5abf4760a
2 files changed
+76
-27
test/sharness/t0066-migration.sh
-27
@@ -49,31 +49,4 @@ test_expect_success "output looks good" '
49
grep "Please get fs-repo-migrations from https://dist.ipfs.io" daemon_out > /dev/null
50
'
51
52
-test_launch_ipfs_daemon
53
-
54
-test_expect_success "build fake dist.ipfs.io" '
55
- mkdir -p fakedist/fs-repo-migrations/v1.0.0/
56
- echo "v1.0.0" > fakedist/fs-repo-migrations/versions
57
-
58
- echo "#!/bin/sh" > fakedist/linux
59
- echo "echo linux $@" >> fakedist/linux
60
- tar -czf fakedist/fs-repo-migrations/fs-repo-migrations_v1.0.0_linux-amd64.tar.gz fakedist/linux
61
-
62
- echo "#!/bin/sh" > fakedist/linux-musl
63
- echo "echo linux-musl $@" >> fakedist/linux-musl
64
- tar -czf fakedist/fs-repo-migrations/fs-repo-migrations_v1.0.0_linux-musl-amd64.tar.gz fakedist/linux-musl
65
-
66
- ipfs add -q -r fakedist/ > fakedisthash
67
-'
68
-
69
-test_expect_success "detect musl" '
70
- IPFS_DIST_PATH="http://172.17.0.1:$GWAY_PORT" echo $IPFS_DIST_PATH
71
-'
72
-
73
-# make fakedist with executables that just echo "I'm $GOOS-$variant with $ARGV"
74
-# ipfs add -r fakedist
75
-# find out IPFS_DIST_PATH
76
-# run daemon --migrate end-to-end
77
-# check for correct output
78
-
52
test_done
test/sharness/t0301-docker-migrate.sh
new
+76
@@ -0,0 +1,76 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2017 Whyrusleeping
4
+# MIT Licensed; see the LICENSE file in this repository.
5
+#
6
+
7
+test_description="Test docker image migration"
8
+
9
+. lib/test-lib.sh
10
+
11
+# if in travis CI on OSX, docker is not available
12
+if ! test_have_prereq DOCKER; then
13
+ skip_all='skipping docker tests, docker not available'
14
+
15
+ test_done
16
+fi
17
+
18
+TEST_TRASH_DIR=$(pwd)
19
+TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR")
20
+TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR")
21
+APP_ROOT_DIR=$(dirname "$TEST_TESTS_DIR")
22
+
23
+test_expect_success "docker image build succeeds" '
24
+ docker_build "$TEST_TESTS_DIR/../Dockerfile.fast" "$APP_ROOT_DIR" >actual &&
25
+ IMAGE_ID=$(tail -n1 actual | cut -d " " -f 3)
26
+'
27
+
28
+test_init_ipfs
29
+
30
+test_expect_success "make repo be version 4" '
31
+ echo 4 > "$IPFS_PATH/version"
32
+'
33
+
34
+test_expect_success "setup http response" '
35
+ echo "HTTP/1.1 200 OK" > vers_resp &&
36
+ echo "Content-Length: 7" >> vers_resp &&
37
+ echo "" >> vers_resp &&
38
+ echo "v1.1.1" >> vers_resp
39
+'
40
+
41
+pretend_server() {
42
+ cat vers_resp | nc -l -i 1 -p 17233
43
+}
44
+
45
+test_expect_success "startup fake dists server" '
46
+ pretend_server > dist_serv_out &
47
+ echo $! > netcat_pid
48
+'
49
+
50
+test_expect_success "docker image runs" '
51
+ DOC_ID=$(docker run -d -v "$IPFS_PATH":/data/ipfs --net=host -e IPFS_DIST_PATH="http://localhost:17233" "$IMAGE_ID" --migrate)
52
+'
53
+
54
+test_expect_success "docker container tries to pull migrations from netcat" '
55
+ sleep 4 &&
56
+ cat dist_serv_out
57
+'
58
+
59
+test_expect_success "see logs" '
60
+ docker logs $DOC_ID
61
+'
62
+
63
+test_expect_success "stop docker container" '
64
+ docker_stop "$DOC_ID"
65
+'
66
+
67
+test_expect_success "kill the net cat" '
68
+ kill $(cat netcat_pid) || true
69
+'
70
+
71
+test_expect_success "correct version was requested" '
72
+ grep "/fs-repo-migrations/v1.1.1/fs-repo-migrations_v1.1.1_linux-musl-amd64.tar.gz" dist_serv_out > /dev/null
73
+'
74
+
75
+test_done
76
+