MCPcopy
hub / github.com/cli/cli / createTestDir

Function createTestDir

pkg/cmdutil/args_test.go:207–251  ·  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

205// |-- subDir2_file.go
206// |-- subDir2_file.txt
207func createTestDir(t *testing.T) (cleanupFn func()) {
208 t.Helper()
209 // Make Directories
210 rootDir := t.TempDir()
211
212 // Move workspace to temporary directory
213 t.Chdir(rootDir)
214
215 // Make subdirectories
216 err := os.Mkdir(filepath.Join(rootDir, "subDir1"), 0755)
217 if err != nil {
218 t.Fatal(err)
219 }
220
221 err = os.Mkdir(filepath.Join(rootDir, "subDir2"), 0755)
222 if err != nil {
223 t.Fatal(err)
224 }
225
226 // Make Files
227 err = os.WriteFile(filepath.Join(rootDir, "rootFile.txt"), []byte(""), 0644)
228 if err != nil {
229 t.Fatal(err)
230 }
231
232 err = os.WriteFile(filepath.Join(rootDir, "subDir1", "subDir1_file.txt"), []byte(""), 0o644)
233 if err != nil {
234 t.Fatal(err)
235 }
236
237 err = os.WriteFile(filepath.Join(rootDir, "subDir2", "subDir2_file.go"), []byte(""), 0o644)
238 if err != nil {
239 t.Fatal(err)
240 }
241
242 err = os.WriteFile(filepath.Join(rootDir, "subDir2", "subDir2_file.txt"), []byte(""), 0o644)
243 if err != nil {
244 t.Fatal(err)
245 }
246
247 cleanupFn = func() {
248 os.RemoveAll(rootDir)
249 }
250 return cleanupFn
251}

Callers 1

TestGlobPathsFunction · 0.85

Calls 2

JoinMethod · 0.80
HelperMethod · 0.65

Tested by

no test coverage detected