| 30 | } |
| 31 | |
| 32 | func TestMountRelative(t *testing.T) { |
| 33 | for _, testcase := range []struct { |
| 34 | name string |
| 35 | path string |
| 36 | bind string |
| 37 | }{ |
| 38 | { |
| 39 | name: "Current path", |
| 40 | path: ".", |
| 41 | bind: "type=bind,source=.,target=/target", |
| 42 | }, |
| 43 | { |
| 44 | name: "Current path with slash", |
| 45 | path: "./", |
| 46 | bind: "type=bind,source=./,target=/target", |
| 47 | }, |
| 48 | { |
| 49 | name: "Parent path with slash", |
| 50 | path: "../", |
| 51 | bind: "type=bind,source=../,target=/target", |
| 52 | }, |
| 53 | { |
| 54 | name: "Parent path", |
| 55 | path: "..", |
| 56 | bind: "type=bind,source=..,target=/target", |
| 57 | }, |
| 58 | } { |
| 59 | t.Run(testcase.name, func(t *testing.T) { |
| 60 | var m MountOpt |
| 61 | assert.NilError(t, m.Set(testcase.bind)) |
| 62 | |
| 63 | mounts := m.Value() |
| 64 | assert.Assert(t, is.Len(mounts, 1)) |
| 65 | abs, err := filepath.Abs(testcase.path) |
| 66 | assert.NilError(t, err) |
| 67 | assert.Check(t, is.DeepEqual(mount.Mount{ |
| 68 | Type: mount.TypeBind, |
| 69 | Source: abs, |
| 70 | Target: "/target", |
| 71 | }, mounts[0])) |
| 72 | }) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // TestMountOptSourceTargetAliases tests several aliases that should have |
| 77 | // the same result. |