Skip to content

Add MockDir to use util::Path in unit tests - #76

Open
lforchini wants to merge 2 commits into
fix-double-path-bugfrom
test/test-utils
Open

lforchini wants to merge 2 commits into
fix-double-path-bugfrom
test/test-utils

Conversation

@lforchini

@lforchini lforchini commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Ensure concurrently running unit tests get independent temporary working
directories. Previously, a process-wide static would make all paths use
the same prefix, causing unit tests to share a working directory.

Create a fixture which hooks into the custom prefix Path system, but
doesn't require an env var to control it. Instead, unit tests can create
a MockDir which will then control the path prefix.

Signed-off-by: Leonardo Forchini leonardo.forchini@nutanix.com

@lforchini
lforchini added this pull request to stack #83 October 1, 2026 14:37
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from 74da0ec to 703d3ea Compare October 1, 2026 14:48
@lforchini
lforchini removed this pull request from stack #83 October 1, 2026 14:50
@lforchini
lforchini added this pull request to stack #84 October 1, 2026 14:50
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from 703d3ea to 91e6361 Compare October 5, 2026 08:10
@lforchini
lforchini removed this pull request from stack #84 October 5, 2026 08:12
@lforchini
lforchini added this pull request to stack #87 October 5, 2026 08:16
@lforchini
lforchini marked this pull request as ready for review October 5, 2026 08:26
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from 91e6361 to 8edfe60 Compare October 5, 2026 08:49
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from 8edfe60 to 9c5ecd0 Compare October 8, 2026 07:30
@lforchini
lforchini removed this pull request from stack #87 October 8, 2026 15:22
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from 9c5ecd0 to ecb32ff Compare October 8, 2026 15:23
@lforchini
lforchini added this pull request to stack #88 October 8, 2026 15:23
@lforchini
lforchini removed this pull request from stack #88 October 13, 2026 12:32
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from ecb32ff to afac66f Compare October 13, 2026 12:43
@lforchini
lforchini added this pull request to stack #95 October 13, 2026 12:44
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from afac66f to f1b373f Compare October 13, 2026 13:17
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from f1b373f to c353351 Compare October 13, 2026 13:29
@lforchini
lforchini force-pushed the test/refactor-config-loading branch from c353351 to 31314b7 Compare October 13, 2026 14:02
@lforchini
lforchini added this pull request to stack #159 October 23, 2026 08:50
@lforchini
lforchini force-pushed the fix-double-path-bug branch from 82c32e8 to 7628305 Compare October 29, 2026 14:29
@lforchini
lforchini removed this pull request from stack #159 October 30, 2026 10:48
@lforchini
lforchini force-pushed the fix-double-path-bug branch from 7628305 to fc21251 Compare October 30, 2026 10:49
@lforchini
lforchini added this pull request to stack #173 October 30, 2026 10:50
@lforchini
lforchini removed this pull request from stack #173 November 5, 2026 15:02
@lforchini
lforchini force-pushed the fix-double-path-bug branch from fc21251 to e5ce185 Compare November 5, 2026 15:03
@lforchini
lforchini added this pull request to stack #176 November 5, 2026 15:03
@lforchini
lforchini removed this pull request from stack #176 November 5, 2026 15:09
@lforchini
lforchini force-pushed the fix-double-path-bug branch from e5ce185 to 7923751 Compare November 5, 2026 15:10
@lforchini
lforchini added this pull request to stack #178 November 5, 2026 15:10
@lforchini
lforchini removed this pull request from stack #178 November 6, 2026 10:23
@lforchini
lforchini force-pushed the fix-double-path-bug branch from 7923751 to be6f7e9 Compare November 6, 2026 10:24
@lforchini
lforchini added this pull request to stack #180 November 6, 2026 10:24
@lforchini
lforchini force-pushed the test/test-utils branch 3 times, most recently from 0e5f4de to 8aa766e Compare November 13, 2026 09:55

@tmakatos tmakatos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reword the commit message to state first what the problem is?

Comment thread src/test/mockdir.rs
pub static ROOT_OVERRIDE: RefCell<Option<PathBuf>> = const { RefCell::new(None) };
}

/// Scoped root override for tests that access absolute paths through

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get what you mean by "scoped" here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The per-thread prefix is only overwritten for as long as this guard exists so I think scoped is the right word here.

Comment thread src/test/mockdir.rs Resolved
Comment thread src/test/mockdir.rs Outdated
}

/// Override the root used by `util::Path` on the current test thread.
pub(crate) fn override_root(root: impl Into<PathBuf>) -> RootOverride {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume this replaces the first absolute component with root?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't replace the first component, it changes what the thread local override is and new paths will be prefixed with root. I've updated the comment to clarify.

Comment thread src/test/mockdir.rs Outdated
}

/// Override the root used by `util::Path` on the current test thread.
pub(crate) fn override_root(root: impl Into<PathBuf>) -> RootOverride {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why is this a free function and not in impl MockDir?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's independent of MockDir. It doesn't need to be pub(crate) so I've dropped that.

Comment thread src/controller.rs Resolved
Comment thread src/path.rs Resolved
Comment thread src/path.rs Resolved
@lforchini
lforchini force-pushed the test/test-utils branch 2 times, most recently from 4f1c2af to 79bf436 Compare November 16, 2026 10:10
Ensure concurrently running unit tests get independent temporary working
directories. Previously, a process-wide static would make all paths use
the same prefix, causing unit tests to share a working directory.

Create a fixture which hooks into the custom prefix Path system, but
doesn't require an env var to control it. Instead, unit tests can create
a MockDir which will then control the path prefix.

Signed-off-by: Leonardo Forchini <leonardo.forchini@nutanix.com>
Signed-off-by: Leonardo Forchini <leonardo.forchini@nutanix.com>
@lforchini lforchini changed the title Add shared test fixtures and helper functions Add MockDir to use util::Path in unit tests Nov 16, 2026
@lforchini
lforchini removed this pull request from stack #180 November 16, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants