Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jtmcg
Copy link

@jtmcg jtmcg commented Dec 23, 2024

Changes

This builds on cli#10124, where @hoffm has begun implementing the gh repo autolink feature set. In particular, this is in response to this PR comment: it refactors the design of the http handler to an interface pattern. This allows for much simpler testing by leveraging dependency injection for listRun().

This addresses a pain-point in the current testing pattern in the repo, where the httpmock pattern is used for testing commands, creating difficult to understand and maintain testing suites.

Hopefully the advantages of this approach are apparent in the simplicity of the tests and can be leveraged for the rest of the gh repo autolink commands.

Testing

  1. Build the binary with make
  2. Run bin/gh repo autolink list -R <OWNER/REPO>

The unit tests do a great job of giving me confidence that this is performing as expected, now, and that confidence should translate to any changes to the peripheral functionality in the command set.

…ting

This defines an AutolinkClient interface with a Get method used for
fetching the autolinks lists from the api. Then, the http client for
autolinks implements this interface with the AutolinkGetter struct.

This allows for dependency injection of the AutolinkGetter struct into the
listOptions, enabling mocking of the AutolinkGetter for testing. The
result of this is simpler tests that are easier to maintain, because the
interface for the table tests now allow for defining autolink structs as
the response instead of large mocked api calls.

This also allows for bespoke testing of the http file, which I'll follow
up with in the next commit.
This adds the missing mocked http tests to the http_test.go file. These
tests were previously bundled with the tests in list_test.go, creating a
testing pattern that was difficult to understand and maintain. The
refactor in the previous commit replaced these tests with the
AutolinkClient interface, allowing for the httpmocks to be isolated to the
AutolinkGetter that implements that interface.
Copy link
Owner

@hoffm hoffm left a comment

Choose a reason for hiding this comment

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

Big improvement. Thank you!

@hoffm hoffm merged commit 512bffe into hoffm:autolink-references Dec 24, 2024
hoffm pushed a commit that referenced this pull request Jan 6, 2025
Fixed test for stdout in non-tty use case of repo fork
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