-
Notifications
You must be signed in to change notification settings - Fork 3
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
refactor: updates Package Structure, Add Interfaces, and Enhance Testing #29
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Removed main_test.go as its functionality is now integrated into more specific test files.
Removed main.go file to migrate functionality to the more appropriately named cli/main.go.
Define a configuration struct for command line options to manage and parse command line arguments effectively.
Introduce interfaces for content reading and clipboard writing to enhance flexibility and testability.
Refactor command line argument handling into a dedicated CLI package for improved organization and clarity.
- Modify the Run function to accept a ClipboardWriter as a parameter instead of creating a DefaultClipboardWriter directly. This would enable easier mocking of the clipboard for testing.
This commit introduces a new `tests/clipper_test.go` file, which includes comprehensive unit tests for the clipper package. The tests cover various components including: - FileContentReader: Reads content from a file. - StdinContentReader: Reads content from standard input. - DefaultClipboardWriter: Writes content to the clipboard. - ParseContent: Parses content from multiple sources, including direct text, files, and invalid inputs. Additionally, the tests use helper functions for creating temporary files and replacing stdin, improving readability and maintainability.
supitsdu
added
enhancement
New feature requests or enhancements.
testing
Issues or PRs specifically related to Go testing frameworks or practices.
refactoring
Issues or PRs to improving code structure, without changing its external behavior
under review
Issues or PRs currently under evaluation and discussion.
cleanup
Minor changes to remove dead code, fix inconsistencies, etc.
labels
Jun 27, 2024
ccoVeille
reviewed
Jun 27, 2024
Skipping clipboard test in short mode. Helps avoid errors when on CI environments.
…and exiting - Refactored the `Run` function to return a `string` (representing the success message or version information) and an `error`. - This change allows the caller of `Run` to handle the output and errors gracefully, rather than relying on `Run` to print messages and exit directly. - Updated the error handling to use `fmt.Errorf` with error wrapping (%w) for better context. - This improvement enhances the flexibility and testability of the `clipper` tool.
… values - Modified the `main` function to call `clipper.Run` and handle both the returned message and error. - Prints the success message if no error occurred, or an error message if an error was encountered. - Exits with a status code of 0 for success or 1 for errors. - This change ensures that the `main` function gracefully handles the output and errors generated by the `Run` function.
ccoVeille
reviewed
Jun 28, 2024
- Introduced a new function `GetReaders` in `clipper.go` to handle the logic of creating `ContentReader` instances based on command-line arguments. - This refactoring improves the readability and maintainability of the `Run` function by separating out a specific task. - The `Run` function now calls `GetReaders` to obtain the necessary readers, making its logic more focused and concise.
supitsdu
added
in-progress
Issues or PRs currently being worked on.
and removed
under review
Issues or PRs currently under evaluation and discussion.
labels
Jun 28, 2024
This was referenced Jun 28, 2024
Closed
ccoVeille
suggested changes
Jun 28, 2024
|
||
if msg != "" { | ||
fmt.Printf("Clipper %s\n", msg) | ||
os.Exit(0) |
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.
No need for this one
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
cleanup
Minor changes to remove dead code, fix inconsistencies, etc.
enhancement
New feature requests or enhancements.
in-progress
Issues or PRs currently being worked on.
refactoring
Issues or PRs to improving code structure, without changing its external behavior
testing
Issues or PRs specifically related to Go testing frameworks or practices.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses a few key changes (See more #24) and significantly improves the code structure and testability of
clipper
.Key Changes:
main
toclipper
for better clarity and consistency.ContentReader
andClipboardWriter
interfaces to improve flexibility and allow for different content sources and clipboard implementations.options
package to centralize command-line argument parsing and configuration management.Run
function now accepts aClipboardWriter
as a parameter, enabling easier mocking in tests.clipper
package to ensure the correctness of file reading, clipboard writing, and content parsing logic.Additional Changes:
main.go
andmain_test.go
files, as their functionality has been migrated to the new structure.Benefits:
Resolves #24
How to Test:
go test ./...
. All tests should pass.Screenshots/GIFs (optional):
Checklist:
Additional Notes:
This pull request is a major step towards a more modular, testable, and maintainable codebase for the
clipper
tool. It sets the foundation for future enhancements and features.