Skip to content

Factory cleanup#3841

Merged
samcoe merged 2 commits intotrunkfrom
factory-cleanup
Jun 15, 2021
Merged

Factory cleanup#3841
samcoe merged 2 commits intotrunkfrom
factory-cleanup

Conversation

@samcoe
Copy link
Contributor

@samcoe samcoe commented Jun 15, 2021

This PR is a small refactor of factory/default for readability and testability. There are no behavioral changes. I have often looked at factory/default and found it confusing and hard to parse, additionally it was untested. The changes I have made here make things more clear and I added a lot of test coverage specifically around the three BaseRepo functions. Lastly, due to this refactor I was able to move the setup of iostreams prompt and iostreams pager out of main and into the factory/default which allowed that functionality to finally be tested.

@samcoe samcoe self-assigned this Jun 15, 2021
@samcoe samcoe force-pushed the factory-cleanup branch from 34b6cf8 to aa9587b Compare June 15, 2021 02:49
@samcoe samcoe marked this pull request as ready for review June 15, 2021 12:29
@samcoe samcoe requested a review from a team June 15, 2021 12:30
}
}

func SmartBaseRepoFunc(f *cmdutil.Factory) func() (ghrepo.Interface, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Formerly resolvedBaseRepo I moved this to be near the other BaseRepo function.

}
}

func OverrideBaseRepoFunc(f *Factory, override string) func() (ghrepo.Interface, error) {
Copy link
Contributor Author

@samcoe samcoe Jun 15, 2021

Choose a reason for hiding this comment

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

I extracted this function for testing purposes. I wanted to move this into default to live with the other two BaseRepo functions but ended up with a circular import dependency so I left it here for now.

s.pagerCommand = cmd
}

func (s *IOStreams) GetPager() string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added for testing purposes.

return s.IsStdinTTY() && s.IsStdoutTTY()
}

func (s *IOStreams) GetNeverPrompt() bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added for testing purposes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't testing be achieved through CanPrompt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, definitely could. My thought was that there is additional logic s.IsStdinTTY() && s.IsStdoutTTY() in CanPrompt and adding this accessor function was a more direct test since I really just wanted to check that SetNeverPrompt(true) had been called in the test.

@samcoe samcoe force-pushed the factory-cleanup branch from aa9587b to edfac42 Compare June 15, 2021 13:20
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

This looks good! Thanks for taking the time to write tests for all of this 💯

return s.IsStdinTTY() && s.IsStdoutTTY()
}

func (s *IOStreams) GetNeverPrompt() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't testing be achieved through CanPrompt?

@samcoe samcoe merged commit d299b74 into trunk Jun 15, 2021
@samcoe samcoe deleted the factory-cleanup branch June 15, 2021 16:10
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