Skip graphdriver/quota TestBlockDev if dependencies are not available
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"path/filepath" |
| 11 | 11 |
"testing" |
| 12 | 12 |
|
| 13 |
+ "github.com/gotestyourself/gotestyourself/fs" |
|
| 13 | 14 |
"github.com/stretchr/testify/assert" |
| 14 | 15 |
"github.com/stretchr/testify/require" |
| 15 | 16 |
"golang.org/x/sys/unix" |
| ... | ... |
@@ -22,7 +23,7 @@ const imageSize = 64 * 1024 * 1024 |
| 22 | 22 |
func TestBlockDev(t *testing.T) {
|
| 23 | 23 |
mkfs, err := exec.LookPath("mkfs.xfs")
|
| 24 | 24 |
if err != nil {
|
| 25 |
- t.Fatal("mkfs.xfs not installed")
|
|
| 25 |
+ t.Skip("mkfs.xfs not found in PATH")
|
|
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 | 28 |
// create a sparse image |
| ... | ... |
@@ -52,18 +53,11 @@ func TestBlockDev(t *testing.T) {
|
| 52 | 52 |
t.Fatal(err) |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 |
- runTest(t, "testBlockDevQuotaDisabled", wrapMountTest(imageFileName, false, testBlockDevQuotaDisabled)) |
|
| 56 |
- runTest(t, "testBlockDevQuotaEnabled", wrapMountTest(imageFileName, true, testBlockDevQuotaEnabled)) |
|
| 57 |
- runTest(t, "testSmallerThanQuota", wrapMountTest(imageFileName, true, wrapQuotaTest(testSmallerThanQuota))) |
|
| 58 |
- runTest(t, "testBiggerThanQuota", wrapMountTest(imageFileName, true, wrapQuotaTest(testBiggerThanQuota))) |
|
| 59 |
- runTest(t, "testRetrieveQuota", wrapMountTest(imageFileName, true, wrapQuotaTest(testRetrieveQuota))) |
|
| 60 |
-} |
|
| 61 |
- |
|
| 62 |
-func runTest(t *testing.T, testName string, testFunc func(*testing.T)) {
|
|
| 63 |
- if success := t.Run(testName, testFunc); !success {
|
|
| 64 |
- out, _ := exec.Command("dmesg").CombinedOutput()
|
|
| 65 |
- t.Log(string(out)) |
|
| 66 |
- } |
|
| 55 |
+ t.Run("testBlockDevQuotaDisabled", wrapMountTest(imageFileName, false, testBlockDevQuotaDisabled))
|
|
| 56 |
+ t.Run("testBlockDevQuotaEnabled", wrapMountTest(imageFileName, true, testBlockDevQuotaEnabled))
|
|
| 57 |
+ t.Run("testSmallerThanQuota", wrapMountTest(imageFileName, true, wrapQuotaTest(testSmallerThanQuota)))
|
|
| 58 |
+ t.Run("testBiggerThanQuota", wrapMountTest(imageFileName, true, wrapQuotaTest(testBiggerThanQuota)))
|
|
| 59 |
+ t.Run("testRetrieveQuota", wrapMountTest(imageFileName, true, wrapQuotaTest(testRetrieveQuota)))
|
|
| 67 | 60 |
} |
| 68 | 61 |
|
| 69 | 62 |
func wrapMountTest(imageFileName string, enableQuota bool, testFunc func(t *testing.T, mountPoint, backingFsDev string)) func(*testing.T) {
|
| ... | ... |
@@ -74,25 +68,22 @@ func wrapMountTest(imageFileName string, enableQuota bool, testFunc func(t *test |
| 74 | 74 |
mountOptions = mountOptions + ",prjquota" |
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 |
- // create a mountPoint |
|
| 78 |
- mountPoint, err := ioutil.TempDir("", "xfs-mountPoint")
|
|
| 79 |
- if err != nil {
|
|
| 80 |
- t.Fatal(err) |
|
| 81 |
- } |
|
| 82 |
- defer os.RemoveAll(mountPoint) |
|
| 77 |
+ mountPointDir := fs.NewDir(t, "xfs-mountPoint") |
|
| 78 |
+ defer mountPointDir.Remove() |
|
| 79 |
+ mountPoint := mountPointDir.Path() |
|
| 83 | 80 |
|
| 84 | 81 |
out, err := exec.Command("mount", "-o", mountOptions, imageFileName, mountPoint).CombinedOutput()
|
| 85 |
- if len(out) > 0 {
|
|
| 86 |
- t.Log(string(out)) |
|
| 87 |
- } |
|
| 88 | 82 |
if err != nil {
|
| 89 |
- t.Fatal("mount failed")
|
|
| 83 |
+ _, err := os.Stat("/proc/fs/xfs")
|
|
| 84 |
+ if os.IsNotExist(err) {
|
|
| 85 |
+ t.Skip("no /proc/fs/xfs")
|
|
| 86 |
+ } |
|
| 90 | 87 |
} |
| 91 | 88 |
|
| 89 |
+ require.NoError(t, err, "mount failed: %s", out) |
|
| 90 |
+ |
|
| 92 | 91 |
defer func() {
|
| 93 |
- if err := unix.Unmount(mountPoint, 0); err != nil {
|
|
| 94 |
- t.Fatal(err) |
|
| 95 |
- } |
|
| 92 |
+ require.NoError(t, unix.Unmount(mountPoint, 0)) |
|
| 96 | 93 |
}() |
| 97 | 94 |
|
| 98 | 95 |
backingFsDev, err := makeBackingFsDev(mountPoint) |