-
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature add go vet #32
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
Conversation
Adds `go vet ./...` to the `test` task in Taskfile.yml to ensure static analysis is performed during testing.
Adds `go vet`, race detection, and fuzz testing to the GitHub Actions workflow. This will improve the quality and robustness of the codebase.
Adds `go vet` to the test procedures in both the local `Taskfile.yml` and the GitHub Actions workflow. Also includes the following changes: - Refactors the `trix` CLI to use the `cobra` library to improve testability. - Adds comprehensive tests for the `trix` CLI, achieving 100% test coverage. - Fixes a closure bug in the sigil command creation loop. - Refactors the CLI to use Cobra's I/O writers, making the output testable.
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughMigrates CLI from clir to Cobra with new subcommands (encode, decode, hash, dynamic sigils); adds IsHashAlgo validator; introduces go vet and a separate fuzz job in CI; alters Taskfile test task to run Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant CLI as trix (root)
participant Sub as Subcommand
participant H as RunE Handler
participant Core as trix/crypt logic
participant IO as Stdout/File
U->>CLI: trix [command] [flags]
CLI->>Sub: select subcommand
Sub->>Sub: parse flags (input/output/magic)
Sub->>H: invoke RunE
H->>H: determine input source (stdin/file/string)
H->>Core: process payload (encode/decode/hash/sigil)
Core-->>H: result / error
alt success
H->>IO: write result
IO-->>U: output
else error
H-->>CLI: return error
CLI-->>U: exit non‑zero
end
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
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.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
cmd/trix/main.go (2)
5-5: Replace deprecatedioutilpackage.The
ioutilpackage has been deprecated since Go 1.16. Functions have been moved toioandospackages:
ioutil.ReadAll→io.ReadAllioutil.ReadFile→os.ReadFileioutil.WriteFile→os.WriteFileApply this diff:
import ( "fmt" - "io/ioutil" + "io" "os"
162-197: Good validation and I/O handling; replace deprecatedioutilcalls in encode.The magic number validation and stdin/stdout support are well-implemented, but multiple deprecated
ioutilfunctions are used.Apply this diff:
var data []byte var err error if inputFile == "" || inputFile == "-" { - data, err = ioutil.ReadAll(cmd.InOrStdin()) + data, err = io.ReadAll(cmd.InOrStdin()) } else { - data, err = ioutil.ReadFile(inputFile) + data, err = os.ReadFile(inputFile) } if err != nil { return err } t := &trix.Trix{ Header: make(map[string]interface{}), Payload: data, InSigils: sigils, } if err := t.Pack(); err != nil { return err } encoded, err := trix.Encode(t, magicNumber, nil) if err != nil { return err } if outputFile == "" || outputFile == "-" { _, err = cmd.OutOrStdout().Write(encoded) return err } - return ioutil.WriteFile(outputFile, encoded, 0644) + return os.WriteFile(outputFile, encoded, 0644)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (6)
.github/workflows/go.yml(1 hunks)Taskfile.yml(1 hunks)cmd/trix/main.go(3 hunks)cmd/trix/main_test.go(1 hunks)go.mod(1 hunks)pkg/crypt/crypt.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
pkg/crypt/crypt.go (3)
pkg/crypt/std/rsa/rsa.go (1)
Service(13-13)examples/main.go (1)
demoHashing(129-148)tdd/crypt/crypt_test.go (3)
TestHash_Good(15-22)TestHash_Bad(24-29)TestHash_Ugly(31-47)
cmd/trix/main.go (3)
pkg/enchantrix/sigils.go (3)
NewSigil(193-246)s(79-89)s(45-49)pkg/crypt/crypt.go (2)
NewService(23-27)HashType(30-30)pkg/trix/trix.go (2)
Trix(30-36)Decode(103-176)
cmd/trix/main_test.go (1)
tdd/trix/trix_test.go (5)
TestTrixEncodeDecode_Good(14-33)TestChecksum_Good(178-190)TestPackUnpack_Good(129-144)interface{}(15-15)interface{}(233-233)
🔇 Additional comments (12)
Taskfile.yml (1)
7-7: LGTM! Excellent addition of static analysis.Adding
go vetbefore tests ensures that static analysis issues are caught early in the development workflow, aligning perfectly with the CI/CD changes.go.mod (1)
6-6: LGTM! Dependency migration to Cobra is correct.The replacement of clir with Cobra v1.10.1 and its indirect dependencies (mousetrap, pflag) correctly supports the CLI refactoring implemented in cmd/trix/main.go.
Also applies to: 13-13, 15-15
pkg/crypt/crypt.go (1)
42-50: LGTM! Hash algorithm validation is correctly implemented.The
IsHashAlgomethod properly validates against all definedHashTypeconstants (LTHN, SHA512, SHA256, SHA1, MD5) and provides the necessary validation support for the CLI hash command..github/workflows/go.yml (1)
26-33: LGTM! Comprehensive CI/CD improvements.The three-step approach (Vet → Test with race detection → Fuzz) significantly enhances code quality assurance. The combination of
-racewith-covermode=atomicis correct, and the 10-second fuzz testing provides good coverage without excessive runtime.cmd/trix/main.go (3)
50-76: LGTM! Well-structured command initialization.The flag definitions and dynamic sigil command generation are well-organized. The approach of creating commands for each sigil type in a loop is clean and maintainable.
78-89: LGTM! Clean command execution pattern.The closure-based
createSigilRunEhelper and the testablemainfunction (using theexitvariable) demonstrate good design practices for CLI applications.
91-108: LGTM! Consistent command handler pattern.The RunE handlers correctly delegate to their respective
handle*functions. Ignoring errors fromGetStringis acceptable as these flags have defaults and Cobra ensures they exist.cmd/trix/main_test.go (5)
13-35: LGTM! Well-designed test helper functions.The test helpers properly configure Cobra commands for testing, with
executeCommandWithStdincorrectly resetting stdin after execution to prevent test pollution. This is essential for reliable test execution.
37-41: LGTM! Good baseline test for root command.This test ensures the root command help text is displayed correctly, providing a simple smoke test for the CLI's basic functionality.
43-67: LGTM! Comprehensive encode/decode round-trip test.The test effectively validates the complete encode/decode workflow with sigil transformation. The round-trip test with the "reverse" sigil ensures correctness of the transformation pipeline.
69-91: LGTM! Thorough hash command testing.The test covers both file and stdin input methods, validates correct hash output, and tests error cases (missing arguments, invalid algorithm, non-existent file). This provides excellent coverage of the hash command functionality.
93-106: LGTM! Correct pattern for testing main function.The subprocess pattern using
GO_TEST_MAINenvironment variable is the standard approach for testingmain()functions that callos.Exit, ensuring coverage whilst avoiding premature test termination.
This commit fixes the fuzz test in the GitHub Actions workflow by correctly scoping it to the `pkg/trix` package. The `go test -fuzz` command can only be run on a single package at a time. This also corrects the `-run` flag to ensure the fuzz test is executed correctly.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/go.yml(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
.github/workflows/go.yml (2)
26-27: Static analysis step follows build and precedes tests—best practice.The
go vet ./...step is correctly positioned in the CI pipeline to catch static analysis issues before unit tests run, aligning with the PR objective to introduce go vet into the workflow.
29-30: Race detection with atomic coverage mode is correct.Adding the
-raceflag and-covermode=atomicto the test step is appropriate. Atomic coverage mode prevents instrumentation conflicts that would otherwise occur when both race detection and coverage instrumentation are enabled simultaneously.
No description provided.