Repository navigation
fix: MockFileSystem.GetTempPath() returns real OS temp path by default #1454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bf29359
be27a00
45889b4
4c004fc
f38a4eb
97f5908
217a1d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,10 @@ public class MockFileSystemOptions | |
| /// Flag indicating, if a temporary directory should be created. | ||
| /// </summary> | ||
| public bool CreateDefaultTempDir { get; init; } = true; | ||
|
|
||
| /// <summary> | ||
| /// The temporary directory used by the <see cref="MockFileSystem" />. | ||
| /// Defaults to <see cref="System.IO.Path.GetTempPath()" /> when <see langword="null" /> or empty. | ||
| /// </summary> | ||
| public string TemporaryDirectory { get; init; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things about the new option:
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,7 +219,7 @@ public async Task MockDirectoryInfo_EnumerateFileSystemInfos_ShouldReturnDirecto | |
| { XFS.Path(@"c:\temp\folder\file.txt"), new MockFileData("") }, | ||
| { XFS.Path(@"c:\temp\folder\folder"), new MockDirectoryData() }, | ||
| { XFS.Path(@"c:\temp\folder\older"), new MockDirectoryData() } | ||
| }); | ||
| }, new MockFileSystemOptions { CreateDefaultTempDir = false }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests had to switch off the temp directory because the host's temp path now shows up deeper in enumerations of |
||
|
|
||
| var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\")); | ||
| var result = directoryInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories).ToArray(); | ||
|
|
@@ -236,7 +236,7 @@ public async Task MockDirectoryInfo_EnumerateFileSystemInfos_ShouldReturnDirecto | |
| { XFS.Path(@"c:\temp\folder\file.txt"), new MockFileData("") }, | ||
| { XFS.Path(@"c:\temp\folder\folder"), new MockDirectoryData() }, | ||
| { XFS.Path(@"c:\temp\folder\older"), new MockDirectoryData() } | ||
| }); | ||
| }, new MockFileSystemOptions { CreateDefaultTempDir = false }); | ||
|
|
||
| var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\")); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not use the host's temp path as the default. It makes the mock depend on the machine it runs on: on Windows every
new MockFileSystem()gets something likeC:\Users\<name>\AppData\Local\Temp, on Linux it followsTMPDIR, and ifTEMPis on another drive the mock quietly gets a second drive. The same test then sees a different file tree on each machine, and snapshots pick up user names.The actual bug is only the Unix default (
/temp/instead of/tmp/), so could we fix just that and keep the constant?For your scoped-filesystem case,
new MockFileSystemOptions { TemporaryDirectory = Path.GetTempPath() }gives you the real path explicitly.