| 26 | ) |
| 27 | |
| 28 | func TestFormatMount(t *testing.T) { |
| 29 | activeMounts := make([]mount.ActiveMount, 5) |
| 30 | for i := range activeMounts { |
| 31 | activeMounts[i] = mount.ActiveMount{ |
| 32 | Mount: mount.Mount{ |
| 33 | Source: fmt.Sprintf("/tmp/source/%d", i), |
| 34 | Target: fmt.Sprintf("%d", i), |
| 35 | }, |
| 36 | MountPoint: fmt.Sprintf("/tmp/mp/%d", i), |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | for _, tc := range []struct { |
| 41 | name string |
| 42 | mount mount.Mount |
| 43 | formatted mount.Mount |
| 44 | }{ |
| 45 | { |
| 46 | name: "empty mount", |
| 47 | }, |
| 48 | { |
| 49 | name: "no formatting", |
| 50 | mount: mount.Mount{ |
| 51 | Type: "bind", |
| 52 | Source: "/var/lib/containerd", |
| 53 | Target: "tmp", |
| 54 | }, |
| 55 | formatted: mount.Mount{ |
| 56 | Type: "bind", |
| 57 | Source: "/var/lib/containerd", |
| 58 | Target: "tmp", |
| 59 | }, |
| 60 | }, |
| 61 | { |
| 62 | name: "simple", |
| 63 | mount: mount.Mount{ |
| 64 | Type: "bind", |
| 65 | Source: "{{ mount 0 }}", |
| 66 | Target: "{{ target 0 }}", |
| 67 | }, |
| 68 | formatted: mount.Mount{ |
| 69 | Type: "bind", |
| 70 | Source: "/tmp/mp/0", |
| 71 | Target: "0", |
| 72 | }, |
| 73 | }, |
| 74 | { |
| 75 | name: "overlay", |
| 76 | mount: mount.Mount{ |
| 77 | Type: "overlay", |
| 78 | Source: "overlay", |
| 79 | Options: []string{ |
| 80 | "lowerdir={{ overlay 0 4 }}", |
| 81 | }, |
| 82 | }, |
| 83 | formatted: mount.Mount{ |
| 84 | Type: "overlay", |
| 85 | Source: "overlay", |