-
Couldn't load subscription status.
- Fork 7.3k
Issue/PR Create Template Selection Tests #1311
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
Issue/PR Create Template Selection Tests #1311
Conversation
| RunE: func(c *cobra.Command, args []string) error { | ||
| templateHandler := githubtemplate.GitHubTemplateHandler | ||
| return issueCreate(c, args, &templateHandler) | ||
| }, |
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.
IMO, We can use this trick to stub anything.
No need to create extra command-specific structs, and build them here and pass them to the command, to be read there.
All that is internally handled by cobra here.
| return &cmdOutStreams, err | ||
| } | ||
|
|
||
| func PrepareCommandArguments(command string) (*cobra.Command, []string, *cmdOut, func(), error) { |
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.
This is for setting up the cobra.Command and the args []string, to be directly passed to our functions, so that we can invoke them directly, without relying on cobra to do that.
| "github.com/spf13/pflag" | ||
| ) | ||
|
|
||
| func TestPrepareCommandArguments(t *testing.T) { |
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 hope I have covered all major cases/formats here.
| ExtractContents func(filePath string) []byte | ||
| } | ||
|
|
||
| func findNonLegacy(rootDir string, name string) []string { |
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 unexported these, so that we don't use them directly by mistake, and are reminded to use the handler.
| } | ||
|
|
||
| // GitHubTemplateHandler handles all the template related functionalities | ||
| var GitHubTemplateHandler = TemplateHandler{ |
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.
The handler with the proper working; to be used when not testing.
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.
Thanks for your patience! This changeset is large, so I hope you understand that we might take some time before we dive deeper into this approach and see if it works for us or if we'd want to suggest some changes. 🙇
|
Sure, no problem 😅 👍 |
|
Any updates? Its been quite a few weeks 😅 |
|
@AliabbasMerchant similar apologies as for your other PR: this work got caught by the vortex of our codebase refactor. Are you up for getting this work reconciled with trunk? I think that this testing might actually have become easier as you can now put a template finding helper (for both issue and pr create) into the factory that is passed to commands and inject it in tests. |
|
Okay. Cool. No issues. I kindof lost track amidst the refactoring wave, but hope to resume contributions, seeing that the refactoring part is done, and we are now again open to accept community contributions. 👌 Will do this in 2-3 days and will re-request a review then. |
|
thanks for your patience and understanding, @AliabbasMerchant ! that refactor was sorely needed and there was no elegant way to balance it against incoming PRs. But yes, it's done now; there is still plenty of cleanup we could do but in terms of fundamental changes we don't have anything planned. |
|
@AliabbasMerchant Thank you! Would you be up to consider a potentially simpler avenue of approaching this? The new command structure might make it easier to stub out the current directory in tests, which we could use to point a command to a fixed location on disk where the fixtures for templates reside. That way you wouldn't have to introduce a whole mechanism for mocking template results, and we could keep the diff at minimum. Let me know if you'd like me to sketch out what I had in mind! 🙇 |
|
@mislav Sure. I am planning to do this today. (Sorry for the delay) |
Fixes #956
Replaces #986
I finally figured out how to do this 🥳
(Have organised commits logically, so reviewing commit-wise should be fairly easy; Also, have tried to make sure that there are no breaking changes at any commit)
The first 6 commits are just the prerequisites
The 7th commit contains the sample interactive template selection test
Requesting reviews, especially from @vilmibm and @mislav
(I don't have permissions to request a review via GitHub directly, hence tagging you all 😅 )