refactor: updates Package Structure, Add Interfaces, and Enhance Testing#29
Merged
refactor: updates Package Structure, Add Interfaces, and Enhance Testing#29
Conversation
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.
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.
This was referenced Jun 28, 2024
Closed
ccoVeille
suggested changes
Jun 28, 2024
|
|
||
| if msg != "" { | ||
| fmt.Printf("Clipper %s\n", msg) | ||
| os.Exit(0) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
maintoclipperfor better clarity and consistency.ContentReaderandClipboardWriterinterfaces to improve flexibility and allow for different content sources and clipboard implementations.optionspackage to centralize command-line argument parsing and configuration management.Runfunction now accepts aClipboardWriteras a parameter, enabling easier mocking in tests.clipperpackage to ensure the correctness of file reading, clipboard writing, and content parsing logic.Additional Changes:
main.goandmain_test.gofiles, 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
clippertool. It sets the foundation for future enhancements and features.