MCPcopy
hub / github.com/firecracker-microvm/firecracker-containerd / createTestExtImg

Function createTestExtImg

internal/fsutil.go:51–73  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, extName string, testFiles ...FSImgFile)

Source from the content-addressed store, hash-verified

49}
50
51func 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
76func CreateBlockDevice(ctx context.Context, t testing.TB) (string, func()) {

Callers 1

CreateFSImgFunction · 0.85

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected