GetInterestingTempDirectoryName returns interesting directory name used for testing.
()
| 26 | |
| 27 | // GetInterestingTempDirectoryName returns interesting directory name used for testing. |
| 28 | func 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. |