File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+
3+ basic_test () {
4+ # Setup
5+ BASE=" $( mktemp --directory) "
6+ NAME=" $( basename " $BASE " ) "
7+ if [ -z " $1 " ]; then
8+ VOLATILE=false
9+ else
10+ VOLATILE=true
11+ fi
12+ docker volume create --driver docker-on-top " $NAME " -o base=" $BASE " -o volatile=" $VOLATILE "
13+
14+ # Deferred cleanup
15+ trap ' rm -rf "$BASE"; docker volume rm "$NAME"; trap - RETURN' RETURN
16+
17+ echo 123 > " $BASE " /a
18+ echo 456 > " $BASE " /b
19+
20+ docker run --rm -v " $NAME " :/dot alpine:latest \
21+ sh -e -c '
22+ # Initial data is visible
23+ [ "$(cat /dot/a)" = 123 ]
24+ [ "$(cat /dot/b)" = 456 ]
25+
26+ # My file removal is visible to me
27+ rm /dot/a
28+ [ ! -e /dot/a ]
29+
30+ # My changes are visible to me
31+ echo 789 > /dot/b
32+ [ "$(cat /dot/b)" = 789 ]
33+
34+ # My new files are visible to me
35+ echo etc > /dot/c
36+ [ "$(cat /dot/c)" = etc ]
37+ '
38+
39+ # Changes are not visible from the host
40+ [ " $( cat " $BASE " /a) " = 123 ]
41+ [ " $( cat " $BASE " /b) " = 456 ]
42+ [ ! -e " $BASE " /c ]
43+
44+ if $VOLATILE ; then
45+ # For a volatile volume, changes should not be visible
46+ [ " $( docker run --rm -v " $NAME " :/dot alpine:latest sh -c ' cat /dot/*' ) " = " $( echo 123; echo 456) " ]
47+ else
48+ # For a regular volume, changes should remain
49+ [ " $( docker run --rm -v " $NAME " :/dot alpine:latest sh -c ' cat /dot/*' ) " = " $( echo 789; echo etc) " ]
50+ fi
51+ }
52+
53+ @test " Test basic usage" {
54+ basic_test
55+ }
56+
57+ @test " Test volatile basic usage" {
58+ basic_test volatile
59+ }
You can’t perform that action at this time.
0 commit comments