@@ -2,6 +2,7 @@ package container
22
33import (
44 "fmt"
5+ "strings"
56 "testing"
67
78 "github.com/docker/cli/e2e/internal/fixtures"
@@ -148,3 +149,37 @@ func TestRunWithCgroupNamespace(t *testing.T) {
148149 "/bin/grep" , "-q" , "':memory:/$'" , "/proc/1/cgroup" )
149150 result .Assert (t , icmd .Success )
150151}
152+
153+ func TestMountSubvolume (t * testing.T ) {
154+ volName := "test-volume-" + t .Name ()
155+ icmd .RunCommand ("docker" , "volume" , "create" , volName ).Assert (t , icmd .Success )
156+
157+ defer icmd .RunCommand ("docker" , "volume" , "remove" , "-f" , volName ).Assert (t , icmd .Success )
158+
159+ defaultMountOpts := []string {
160+ "type=volume" ,
161+ "src=" + volName ,
162+ "dst=/volume" ,
163+ }
164+
165+ // Populate the volume with test data.
166+ icmd .RunCommand ("docker" , "run" , "--mount" , strings .Join (defaultMountOpts , "," ), fixtures .AlpineImage , "sh" , "-c" ,
167+ "echo foo > /volume/bar.txt && " +
168+ "mkdir /volume/subdir && echo world > /volume/subdir/hello.txt;" ,
169+ ).Assert (t , icmd .Success )
170+
171+ runMount := func (cmd string , mountOpts ... string ) * icmd.Result {
172+ mountArg := strings .Join (append (defaultMountOpts , mountOpts ... ), "," )
173+ return icmd .RunCommand ("docker" , "run" , "--mount" , mountArg , fixtures .AlpineImage , cmd , "/volume" )
174+ }
175+
176+ t .Run ("subpath not exists" , func (t * testing.T ) {
177+ runMount ("ls" , "volume-subpath=some-path/that/doesnt-exist" ).Assert (t , icmd.Expected {Err : "volume's path is not accessible" , ExitCode : 125 })
178+ })
179+ t .Run ("subdirectory mount" , func (t * testing.T ) {
180+ runMount ("ls" , "volume-subpath=subdir" ).Assert (t , icmd.Expected {Out : "hello.txt" })
181+ })
182+ t .Run ("file mount" , func (t * testing.T ) {
183+ runMount ("cat" , "volume-subpath=bar.txt" ).Assert (t , icmd.Expected {Out : "foo" })
184+ })
185+ }
0 commit comments