master
sh 87 lines 2.23 KB
Raw
1 #!/usr/bin/env bash
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 '$test_description', docker not available'
14
15 test_done
16 fi
17
18 if ! test_have_prereq SOCAT; then
19 skip_all="skipping '$test_description': socat is not available"
20 test_done
21 fi
22
23 TEST_TRASH_DIR=$(pwd)
24 TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR")
25 TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR")
26 APP_ROOT_DIR=$(dirname "$TEST_TESTS_DIR")
27 IMAGE_TAG=kubo_migrate
28
29 test_expect_success "docker image build succeeds" '
30 docker_build "$IMAGE_TAG" "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR"
31 '
32
33 test_init_ipfs
34
35 test_expect_success "configure migration sources" '
36 ipfs config --json Migration.DownloadSources "[\"http://127.0.0.1:17233\"]"
37 '
38
39 test_expect_success "setup http response" '
40 mkdir migration &&
41 echo "v1.1.1" > migration/versions &&
42 mkdir -p migration/fs-repo-6-to-7 &&
43 echo "v1.1.1" > migration/fs-repo-6-to-7/versions &&
44 CID=$(ipfs add -r -Q migration) &&
45 echo "HTTP/1.1 200 OK" > vers_resp &&
46 echo "Content-Type: application/vnd.ipld.car" >> vers_resp &&
47 echo "" >> vers_resp &&
48 ipfs dag export $CID >> vers_resp
49 '
50
51 test_expect_success "make repo be version 4" '
52 echo 4 > "$IPFS_PATH/version"
53 '
54
55 test_expect_success "startup fake dists server" '
56 ( socat tcp-listen:17233,fork,bind=127.0.0.1,reuseaddr "SYSTEM:cat vers_resp"!!STDERR 2> dist_serv_out ) &
57 echo $! > netcat_pid
58 '
59
60 test_expect_success "docker image runs" '
61 DOC_ID=$(docker run -d -v "$IPFS_PATH":/data/ipfs -e IPFS_DIST_PATH=/ipfs/$CID --net=host "$IMAGE_TAG")
62 '
63
64 test_expect_success "docker container tries to pull migrations from netcat" '
65 sleep 4 &&
66 cat dist_serv_out
67 '
68
69 test_expect_success "see logs" '
70 docker logs $DOC_ID
71 '
72
73 test_expect_success "stop docker container" '
74 docker_stop "$DOC_ID"
75 '
76
77 test_expect_success "kill the net cat" '
78 kill $(cat netcat_pid) || true
79 '
80
81 test_expect_success "correct version was requested" '
82 grep "/fs-repo-6-to-7/v1.1.1/fs-repo-6-to-7_v1.1.1_linux-amd64.tar.gz" dist_serv_out > /dev/null
83 '
84
85 docker_rm "$DOC_ID"
86 docker_rmi "$IMAGE_TAG"
87 test_done