8000 🧹 chore: Improve tests coverage by gaby · Pull Request #117 · gofiber/utils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🧹 chore: Improve tests coverage #117

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

🧹 chore: Improve tests coverage #117

wants to merge 3 commits into from

Conversation

gaby
Copy link
Member
@gaby gaby commented Jun 15, 2025

Summary

  • Improve coverage of ips.go
  • Improve coverage of file.go

Note

  • These were generated using OpenAI Codex

Summary by CodeRabbit

  • Tests
    • Added comprehensive tests to improve coverage for directory reading and traversal logic, including error handling and edge cases.
    • Introduced additional tests to verify handling of invalid IPv6 address formats.

@gaby gaby requested a review from a team as a code owner June 15, 2025 01:31
@gaby gaby requested review from sixcolors, ReneWerner87 and efectn and removed request for a team June 15, 2025 01:31
Copy link
Contributor
coderabbitai bot commented Jun 15, 2025

Warning

Rate limit exceeded

@gaby has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 76ed8cc and a5019f6.

📒 Files selected for processing (1)
  • file_test.go (2 hunks)

Walkthrough

New tests have been added to improve coverage of directory reading, walking logic, and IPv6 address validation. A custom filesystem wrapper simulating errors was introduced for testing error handling. The IPv6 tests now include additional edge cases to verify correct handling of invalid addresses.

Changes

File(s) Change Summary
file_test.go Added errFS type simulating filesystem errors; introduced multiple tests for directory reading and walking, including error handling and control flow scenarios.
ips_test.go Added Test_IsIPv6_EdgeCases to cover additional invalid IPv6 address scenarios.

Poem

In the warren of tests, new tunnels appear,
With edge-case addresses and files to fear.
A filesystem trick, a skip and a hop,
Ensures every error is caught on the hop!
The IPv6 maze is mapped with care—
Now bugs beware, for rabbits are there! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch improve-coverage
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
coderabbitai bot commented Jun 15, 2025

Walkthrough

The changes introduce new tests to improve coverage of directory and file system handling, as well as IPv6 address validation. A helper type is added to simulate file system errors. The new tests verify error handling, edge cases, and correct behavior in directory traversal and IPv6 parsing logic.

Changes

File(s) Change Summary
file_test.go Added errFS helper type, multiple new test functions for directory reading and walking logic.
ips_test.go Added Test_IsIPv6_EdgeCases to test additional invalid IPv6 address scenarios.

Poem

In the warren of code, new tests now appear,
Checking paths and addresses, both far and near.
With edge cases caught and errors in sight,
The filesystem hops through the darkest of night.
IPv6 quirks and directories, too—
All covered by tests, as good bunnies do! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch improve-coverage
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving the test coverage for utility functions related to file system operations and IP address validation. It adds new test cases to cover previously untested code paths and edge cases, enhancing the robustness of these components.

Highlights

  • File System Testing: Added comprehensive tests for internal file system utility functions like readDirNames, readDir, and walkInternal in file.go.
  • IPv6 Validation Edge Cases: Added new test cases to ips.go specifically targeting edge cases and invalid formats for IPv6 address validation.
  • Test Helper: Introduced a custom errFS type in file_test.go to facilitate testing error handling paths in file system operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
file_test.go (1)

3-13: ⚠️ Potential issue

Missing errors import breaks the build

errors.New is used below (lines 155 and 190) but the package is not imported, causing the compile error reported by CI (undefined: errors).
Add the import:

 	"io/fs"
 	"net/http"
 	"os"
 	"path/filepath"
+	"errors"
 	"runtime"
 	"testing"
🧹 Nitpick comments (1)
file_test.go (1)

112-115: Order-sensitive assertion may be flaky across filesystems

readDirNames returns a slice whose order depends on the implementation of fs.ReadDir for the supplied filesystem. On some platforms or future Go versions the order could differ (e.g. john.txt before example).
Consider using ElementsMatch (order-agnostic) or explicitly sorting the slice before comparing:

-	require.Equal(t, []string{"example", "john.txt"}, names)
+	require.ElementsMatch(t, []string{"example", "john.txt"}, names)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c22a25 and 932e4cc.

📒 Files selected for processing (2)
  • file_test.go (2 hunks)
  • ips_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
ips_test.go (1)
ips.go (1)
  • IsIPv6 (43-143)
🪛 GitHub Check: Build (1.23.x, macos-latest)
file_test.go

[failure] 190-190:
undefined: errors


[failure] 155-155:
undefined: errors


[failure] 190-190:
undefined: errors


[failure] 155-155:
undefined: errors

🪛 GitHub Check: Compare
file_test.go

[failure] 190-190:
undefined: errors


[failure] 155-155:
undefined: errors

🪛 GitHub Actions: Benchmark
file_test.go

[error] 155-155: Compilation error: undefined identifier 'errors'.

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Analyse
  • GitHub Check: lint
  • GitHub Check: Build (1.24.x, macos-latest)
  • GitHub Check: Build (1.23.x, macos-13)
  • GitHub Check: Build (1.24.x, windows-latest)
  • GitHub Check: Build (1.24.x, ubuntu-latest)
  • GitHub Check: Build (1.24.x, macos-13)
  • GitHub Check: Build (1.23.x, ubuntu-latest)
  • GitHub Check: Build (1.23.x, macos-latest)
  • GitHub Check: Build (1.23.x, windows-latest)
🔇 Additional comments (1)
ips_test.go (1)

79-93: 👍 Extra edge-case coverage looks solid

The new Test_IsIPv6_EdgeCases table probes four tricky failure scenarios that were previously untested and maps cleanly to the guard rails in IsIPv6. This should prevent silent regressions around oversized hex groups, misplaced/oversized embedded IPv4s and misuse of the ellipsis. No issues spotted here.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
file_test.go (1)

3-13: ⚠️ Potential issue

Fix compilation failure – add missing "errors" import.

errors.New is used in Test_walkInternal_Error and Test_walkInternal_StatErrorPropagate, but the package isn’t imported, causing the pipeline error shown in CI.

@@
 	"fmt"
 	"io/fs"
 	"net/http"
 	"os"
+	"errors"
 	"path/filepath"
 	"runtime"
 	"testing"
🧹 Nitpick comments (1)
file_test.go (1)

165-170: Minor: receiver can be pointer to avoid struct copying (optional).

Open uses a value receiver, so every call copies the embedded http.FileSystem and fail string. Copy cost is tiny here, but switching to a pointer receiver aligns with common http.FileSystem wrappers and avoids accidental copies if the struct grows.

-func (e errFS) Open(name string) (http.File, error) {
+func (e *errFS) Open(name string) (http.File, error) {

Call sites remain unchanged.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c22a25 and 932e4cc.

📒 Files selected for processing (2)
  • file_test.go (2 hunks)
  • ips_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
ips_test.go (1)
ips.go (1)
  • IsIPv6 (43-143)
🪛 GitHub Check: Compare
file_test.go

[failure] 190-190:
undefined: errors


[failure] 155-155:
undefined: errors

🪛 GitHub Actions: Benchmark
file_test.go

[error] 155-155: Compilation error: undefined identifier 'errors' in test file.

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Analyse
  • GitHub Check: lint
  • GitHub Check: Build (1.24.x, macos-latest)
  • GitHub Check: Build (1.23.x, macos-13)
  • GitHub Check: Build (1.24.x, windows-latest)
  • GitHub Check: Build (1.24.x, ubuntu-latest)
  • GitHub Check: Build (1.24.x, macos-13)
  • GitHub Check: Build (1.23.x, ubuntu-latest)
  • GitHub Check: Build (1.23.x, macos-latest)
  • GitHub Check: Build (1.23.x, windows-latest)
🔇 Additional comments (1)
ips_test.go (1)

79-93: Edge-case tests add valuable coverage – looks good.
The new inputs correctly target failure branches in IsIPv6 (oversized hex, misplaced/oversized IPv4, malformed ellipsis). No issues spotted.

Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request significantly improves test coverage for file system utilities and IP address validation. The new tests are comprehensive and cover important edge cases and error conditions. A potential issue is the path resolution for test data in file_test.go, which might need adjustment to ensure tests are robust across different environments.

Copy link
codecov bot commented Jun 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.03%. Comparing base (0c22a25) to head (a5019f6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #117      +/-   ##
==========================================
+ Coverage   90.89%   96.03%   +5.14%     
==========================================
  Files           9        9              
  Lines         505      505              
==========================================
+ Hits          459      485      +26     
+ Misses         33       14      -19     
+ Partials       13        6       -7     
Flag Coverage Δ
unittests 96.03% <ø> (+5.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
file_test.go (3)

28-35: Assert the error before inspecting the payload

require.Equal is executed prior to require.NoError.
If ReadFile unexpectedly returns an error, the first assertion will still run (with possibly nil data) and report a confusing mismatch. Swap the order for clearer failure signals.

-	file, err := ReadFile("john.txt", testFS)
+	file, err := ReadFile("john.txt", testFS)
+	require.NoError(t, err)           // fail fast

25-26: Hard-coded relative path risks flakiness

The tests assume they are executed from the repository root (".github/tests").
go test ./... runs each package from its own directory, so this path will be wrong when the
utils package is not at the repo root. Prefer t.TempDir fixtures or embed testdata under the
package’s testdata folder (which Go tooling treats specially).

Example:

testFS := os.DirFS("testdata")

Also applies to: 66-67


166-171: Path comparison may fail on mixed separators

filepath.Clean(name) returns OS-specific separators; when errFS.fail is built with
filepath.Join, both sides should match, but if fail is initialised with a hard-coded
slash ("a/b.txt"), the comparison can miss on Windows.
Consider normalising both strings to forward slashes using filepath.ToSlash for resilience.

if filepath.ToSlash(filepath.Clean(name)) == filepath.ToSlash(e.fail) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 932e4cc and 76ed8cc.

📒 Files selected for processing (1)
  • file_test.go (2 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
file_test.go

[failure] 192-192:
unused-parameter: parameter 'path' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 179-179:
unused-parameter: parameter 'err' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 179-179:
unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 179-179:
unused-parameter: parameter 'path' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 157-157:
unused-parameter: parameter 'err' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 157-157:
unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 142-142:
unused-parameter: parameter 'err' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 142-142:
unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive)

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build (1.23.x, macos-13)
  • GitHub Check: Build (1.24.x, windows-latest)
  • GitHub Check: Build (1.23.x, ubuntu-latest)
  • GitHub Check: Build (1.23.x, macos-latest)
  • GitHub Check: Build (1.24.x, macos-13)
  • GitHub Check: Build (1.24.x, macos-latest)
  • GitHub Check: Build (1.24.x, ubuntu-latest)
  • GitHub Check: Build (1.23.x, windows-latest)
  • GitHub Check: Analyse
  • GitHub Check: Compare

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0