|
9 | 9 | graphdriver "github.com/containers/storage/drivers" |
10 | 10 | "github.com/containers/storage/drivers/graphtest" |
11 | 11 | "github.com/containers/storage/pkg/archive" |
| 12 | + "github.com/containers/storage/pkg/idtools" |
12 | 13 | "github.com/containers/storage/pkg/reexec" |
13 | 14 | "github.com/stretchr/testify/assert" |
14 | 15 | "github.com/stretchr/testify/require" |
@@ -52,6 +53,47 @@ func TestContainersOverlayXattr(t *testing.T) { |
52 | 53 | assert.Equal(t, 0o555&os.ModePerm, fi.Mode()&os.ModePerm, root) |
53 | 54 | } |
54 | 55 |
|
| 56 | +func TestSupportsShifting(t *testing.T) { |
| 57 | + contiguousMap := []idtools.IDMap{ |
| 58 | + { |
| 59 | + ContainerID: 0, |
| 60 | + HostID: 1000, |
| 61 | + Size: 65536, |
| 62 | + }, |
| 63 | + } |
| 64 | + nonContiguousMap := []idtools.IDMap{ |
| 65 | + { |
| 66 | + ContainerID: 0, |
| 67 | + HostID: 0, |
| 68 | + Size: 1, |
| 69 | + }, |
| 70 | + { |
| 71 | + ContainerID: 2, |
| 72 | + HostID: 2, |
| 73 | + Size: 1, |
| 74 | + }, |
| 75 | + } |
| 76 | + |
| 77 | + t.Run("no mount program", func(t *testing.T) { |
| 78 | + driver := graphtest.GetDriver(t, driverName) |
| 79 | + defer graphtest.PutDriver(t) |
| 80 | + |
| 81 | + supported := driver.SupportsShifting(nil, nil) |
| 82 | + assert.Equal(t, supported, driver.SupportsShifting(contiguousMap, contiguousMap), "contiguous map with no mount program") |
| 83 | + assert.Equal(t, supported, driver.SupportsShifting(nonContiguousMap, nonContiguousMap), "non-contiguous map with no mount program") |
| 84 | + }) |
| 85 | + |
| 86 | + t.Run("with mount program", func(t *testing.T) { |
| 87 | + driver := graphtest.GetDriver(t, driverName, "mount_program=/usr/bin/true") |
| 88 | + defer graphtest.PutDriver(t) |
| 89 | + |
| 90 | + assert.True(t, driver.SupportsShifting(nil, nil), "nil map with mount program") |
| 91 | + assert.True(t, driver.SupportsShifting(contiguousMap, contiguousMap), "contiguous map with mount program") |
| 92 | + // If a mount program is specified, SupportsShifting must return false |
| 93 | + assert.False(t, driver.SupportsShifting(nonContiguousMap, nonContiguousMap), "non-contiguous map with mount program") |
| 94 | + }) |
| 95 | +} |
| 96 | + |
55 | 97 | // This avoids creating a new driver for each test if all tests are run |
56 | 98 | // Make sure to put new tests between TestOverlaySetup and TestOverlayTeardown |
57 | 99 | func TestOverlaySetup(t *testing.T) { |
|
0 commit comments