MCPcopy Create free account
hub / github.com/cli/cli / createTestDir

Function createTestDir

pkg/cmdutil/args_test.go:272–316  ·  view source on GitHub ↗

Creates a temporary directory with the structure below. Returns a cleanup function that will remove the directory and all of its contents. The cleanup function should be wrapped in a defer statement. | root |-- rootFile.txt |-- subDir1 | |-- subDir1_file.txt | |-- subDir2 |-- subDir2_file.g

(t *testing.T)

Source from the content-addressed store, hash-verified

270// |-- subDir2_file.go
271// |-- subDir2_file.txt
272func createTestDir(t *testing.T) (cleanupFn func()) {
273 t.Helper()
274 // Make Directories
275 rootDir := t.TempDir()
276
277 // Move workspace to temporary directory
278 t.Chdir(rootDir)
279
280 // Make subdirectories
281 err := os.Mkdir(filepath.Join(rootDir, "subDir1"), 0755)
282 if err != nil {
283 t.Fatal(err)
284 }
285
286 err = os.Mkdir(filepath.Join(rootDir, "subDir2"), 0755)
287 if err != nil {
288 t.Fatal(err)
289 }
290
291 // Make Files
292 err = os.WriteFile(filepath.Join(rootDir, "rootFile.txt"), []byte(""), 0644)
293 if err != nil {
294 t.Fatal(err)
295 }
296
297 err = os.WriteFile(filepath.Join(rootDir, "subDir1", "subDir1_file.txt"), []byte(""), 0o644)
298 if err != nil {
299 t.Fatal(err)
300 }
301
302 err = os.WriteFile(filepath.Join(rootDir, "subDir2", "subDir2_file.go"), []byte(""), 0o644)
303 if err != nil {
304 t.Fatal(err)
305 }
306
307 err = os.WriteFile(filepath.Join(rootDir, "subDir2", "subDir2_file.txt"), []byte(""), 0o644)
308 if err != nil {
309 t.Fatal(err)
310 }
311
312 cleanupFn = func() {
313 os.RemoveAll(rootDir)
314 }
315 return cleanupFn
316}

Callers 1

TestGlobPathsFunction · 0.85

Calls 3

JoinMethod · 0.80
WriteFileMethod · 0.80
HelperMethod · 0.65

Tested by

no test coverage detected