forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht0002-docker-image.sh
executable file
·98 lines (80 loc) · 3.14 KB
/
t0002-docker-image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
#
# Copyright (c) 2015 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test docker image"
. lib/test-lib.sh
# if in travis CI on OSX, docker is not available
if ! test_have_prereq DOCKER; then
skip_all='skipping docker tests, docker not available'
test_done
fi
test_expect_success "'docker --version' works" '
docker --version >actual
'
test_expect_success "'docker --version' output looks good" '
egrep "^Docker version" actual
'
TEST_TRASH_DIR=$(pwd)
TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR")
TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR")
APP_ROOT_DIR=$(dirname "$TEST_TESTS_DIR")
IMAGE_TAG=kubo_test
test_expect_success "docker image build succeeds" '
docker_build "$IMAGE_TAG" "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR" ||
test_fsh echo "TEST_TESTS_DIR: $TEST_TESTS_DIR" ||
test_fsh echo "APP_ROOT_DIR : $APP_ROOT_DIR"
'
test_expect_success "write init scripts" '
echo "ipfs config Provider.Strategy Bar" > 001.sh &&
echo "ipfs config Datastore.Path Qux" > 002.sh &&
chmod +x 002.sh
'
test_expect_success "docker image runs" '
DOC_ID=$(docker run -d \
-p 127.0.0.1:5001:5001 -p 127.0.0.1:8080:8080 \
-v "$PWD/001.sh":/container-init.d/001.sh \
-v "$PWD/002.sh":/container-init.d/002.sh \
"$IMAGE_TAG")
'
test_expect_success "docker container gateway is up" '
pollEndpoint -host=/ip4/127.0.0.1/tcp/8080 -http-url http://localhost:8080/ipfs/bafkqaddimvwgy3zao5xxe3debi -v -tries 30 -tout 1s
'
test_expect_success "docker container API is up" '
pollEndpoint -host=/ip4/127.0.0.1/tcp/5001 -http-url http://localhost:5001/version -v -tries 30 -tout 1s
'
test_expect_success "check that init scripts were run correctly and in the correct order" "
echo -e \"Sourcing '/container-init.d/001.sh'...\nExecuting '/container-init.d/002.sh'...\" > expected &&
docker logs $DOC_ID 2>/dev/null | grep -e 001.sh -e 002.sh > actual &&
test_cmp actual expected
"
test_expect_success "check that init script configs were applied" '
echo Bar > expected &&
docker exec "$DOC_ID" ipfs config Provider.Strategy > actual &&
test_cmp actual expected &&
echo Qux > expected &&
docker exec "$DOC_ID" ipfs config Datastore.Path > actual &&
test_cmp actual expected
'
test_expect_success "simple ipfs add/cat can be run in docker container" '
echo "Hello Worlds" | tr -d "[:cntrl:]" > expected &&
HASH=$(docker_exec "$DOC_ID" "echo $(cat expected) | ipfs add -q" | tr -d "[:cntrl:]") &&
docker_exec "$DOC_ID" "ipfs cat $HASH" | tr -d "[:cntrl:]" > actual &&
test_cmp expected actual
'
read testcode <<EOF
pollEndpoint -host=/ip4/127.0.0.1/tcp/5001 -http-url http://localhost:5001/version -http-out | grep Commit | cut -d" " -f2 >actual ; \
test -s actual ; \
docker exec -i "$DOC_ID" ipfs version --enc json \
| sed 's/^.*"Commit":"\\\([^"]*\\\)".*$/\\\1/g' >expected ; \
test -s expected ; \
test_cmp expected actual
EOF
test_expect_success "version CurrentCommit is set" "$testcode"
test_expect_success "stop docker container" '
docker_stop "$DOC_ID"
'
docker_rm "$DOC_ID"
docker_rmi "$IMAGE_TAG"
test_done