MCPcopy
hub / github.com/kopia/kopia / GetInterestingTempDirectoryName

Function GetInterestingTempDirectoryName

internal/testutil/tmpdir.go:28–50  ·  view source on GitHub ↗

GetInterestingTempDirectoryName returns interesting directory name used for testing.

()

Source from the content-addressed store, hash-verified

26
27// GetInterestingTempDirectoryName returns interesting directory name used for testing.
28func GetInterestingTempDirectoryName() (string, error) {
29 td, err := os.MkdirTemp("", "kopia-test-"+time.Now().UTC().Format("20060102-150405")) //nolint:forbidigo
30 if err != nil {
31 return "", errors.Wrap(err, "unable to create temp directory")
32 }
33
34 //nolint:gosec
35 targetLen := interestingLengths[rand.Intn(len(interestingLengths))]
36
37 // make sure the base directory is quite long to trigger very long filenames on Windows.
38 if n := len(td); n < targetLen {
39 if !ShouldSkipLongFilenames() {
40 td = filepath.Join(td, strings.Repeat("f", targetLen-n))
41 }
42
43 //nolint:mnd
44 if err := os.MkdirAll(td, 0o700); err != nil {
45 return "", errors.Wrap(err, "unable to create temp directory")
46 }
47 }
48
49 return td, nil
50}
51
52// TempDirectory returns an interesting temporary directory and cleans it up before test
53// completes.

Callers 2

oneTimeSetupFunction · 0.92
TempDirectoryFunction · 0.85

Calls 5

ShouldSkipLongFilenamesFunction · 0.85
NowMethod · 0.80
RepeatMethod · 0.80
FormatMethod · 0.65
MkdirAllMethod · 0.65

Tested by 1

oneTimeSetupFunction · 0.74