| 49 | } |
| 50 | |
| 51 | func createTestExtImg(ctx context.Context, t *testing.T, extName string, testFiles ...FSImgFile) string { |
| 52 | t.Helper() |
| 53 | |
| 54 | tempdir, err := os.MkdirTemp("", "") |
| 55 | require.NoError(t, err, "failed to create temp dir for ext img") |
| 56 | |
| 57 | for _, testFile := range testFiles { |
| 58 | destPath := filepath.Join(tempdir, testFile.Subpath) |
| 59 | |
| 60 | err = os.MkdirAll(filepath.Dir(destPath), 0750) |
| 61 | require.NoError(t, err, "failed to mkdir for contents of ext img file") |
| 62 | |
| 63 | err = os.WriteFile(destPath, []byte(testFile.Contents), 0750) |
| 64 | require.NoError(t, err, "failed to write file for contents of ext img") |
| 65 | } |
| 66 | |
| 67 | imgFile, err := os.CreateTemp("", "") |
| 68 | require.NoError(t, err, "failed to obtain temp file for ext img") |
| 69 | |
| 70 | output, err := exec.CommandContext(ctx, "mkfs."+extName, "-d", tempdir, imgFile.Name(), "65536").CombinedOutput() |
| 71 | require.NoErrorf(t, err, "failed to create ext img, command output:\n %s", string(output)) |
| 72 | return imgFile.Name() |
| 73 | } |
| 74 | |
| 75 | // CreateBlockDevice creates a block device, or block special file for testing |
| 76 | func CreateBlockDevice(ctx context.Context, t testing.TB) (string, func()) { |