Skip to content

Teach Enlistment.GetNewGVFSLogFileName to take FileSystem parameter#1071

Merged
jamill merged 1 commit intomicrosoft:masterfrom
jamill:github_upgrader_filesystem
Apr 29, 2019
Merged

Teach Enlistment.GetNewGVFSLogFileName to take FileSystem parameter#1071
jamill merged 1 commit intomicrosoft:masterfrom
jamill:github_upgrader_filesystem

Conversation

@jamill
Copy link
Member

@jamill jamill commented Apr 25, 2019

This will enable the Enlistment.GetNewGVFSLogFileName method to interact with
the file system through the file system abstraction layer, enabling us to unit
test this method and methods that call this method.

With this change, the GitHubUpgrader tests should no longer create actual directories when running the unit tests.

Copy link
Member

@kewillford kewillford left a comment

Choose a reason for hiding this comment

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

Not sure if this helps us with the long term plans with file system.

PhysicalFileSystem fileSystem,
string logsRoot,
string prefix,
string logId = null)
Copy link
Member

Choose a reason for hiding this comment

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

I don't like how this caused a bunch of new PhysicalFileSystem() calls to be added to that callers especially with what we were talking about yesterday with working towards having only one on the context or platform. I haven't look at all the call sites but could we instead change this to not be a static call and pass the file system into the constructor of the Enlistment? Not sure if all the call sites have an enlistment to use though. But that would eventually allow us to mock the GetNewLogFileName if needed. Statics make it really hard for unit testing and mocking.

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't look at all the call sites but could we instead change this to not be a static call and pass the file system into the constructor of the Enlistment?

Not all of the call sites have a GVFSEnlistment instance :) For example, the upgrader is not run in the context of an enlistment, and neither is the service callsites - which maybe hints that the method is not in the most appropriate location.

Statics make it really hard for unit testing and mocking.

Yep - the motiviation for this change is around making the callers of this method more testable :)

Copy link
Member

Choose a reason for hiding this comment

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

Okay thanks!

Copy link
Member

@kewillford kewillford left a comment

Choose a reason for hiding this comment

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

One suggestion. Using new PhysicalFileSystem() in the GetNewLogFileName method will make this change much smaller.

Copy link
Member

@mjcheetham mjcheetham left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

This will enable the Enlistment.GetNewGVFSLogFileName method to interact with
the file system through the file system abstraction layer, enabling us to unit
test this method and methods that call this method.

Instead of updating all call sites to pass in a physical file system,
this is an optional argument. If one is passed in, it will be used. If
no physical file system argument is provided, a default physical file
system object will be created.
@jamill jamill force-pushed the github_upgrader_filesystem branch from 2ede3dc to e75f659 Compare April 29, 2019 14:50
@jamill
Copy link
Member Author

jamill commented Apr 29, 2019

One suggestion. Using new PhysicalFileSystem() in the GetNewLogFileName method will make this change much smaller.

I like the idea of reducing the impact on call sites. I tweaked the method to optionally take in a PhysicalFileSystem, but not require it.

Copy link
Member

@mjcheetham mjcheetham left a comment

Choose a reason for hiding this comment

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

Looks much cleaner/less churn with the new update (fileSystem ?? new PhysicalFS())
👍

@jamill jamill merged commit 0be1369 into microsoft:master Apr 29, 2019
@jrbriggs jrbriggs added this to the M151 milestone May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants