Skip to content
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

[TESTING/CLEANUP] Replace deprecated tenv linter for usetesting #3087

Merged
merged 4 commits into from
Mar 14, 2025

Conversation

GLobyNew
Copy link
Contributor

When I try to run make codequality I receive:

GOLANGCI-LINT WARN The linter 'tenv' is deprecated (since v1.64.0) due to: Duplicate feature in another linter. Replaced by usetesting.

By recommendation above I replaced linter and it showed me new issues:

# https://github.com/gopasspw/gopass/blob/master/Makefile#L136
     GOLANGCI-LINT internal/updater/update_test.go:51:12: os.Setenv() could be replaced by t.Setenv() in TestIsUpdateable (usetesting)
                                return os.Setenv("GOPASS_FORCE_UPDATE", "true")
                                       ^
internal/updater/update_test.go:64:12: os.Setenv() could be replaced by t.Setenv() in TestIsUpdateable (usetesting)
                                return os.Setenv("GOPATH", "/tmp/foo")
                                       ^
pkg/tempfile/file_test.go:49:18: os.MkdirTemp() could be replaced by t.TempDir() in TestTempdirBase (usetesting)
        tempdir, err := os.MkdirTemp(tempdirBase(), "gopass-")
                        ^
tests/tester.go:73:13: os.MkdirTemp() could be replaced by t.TempDir() in newTester (usetesting)
        td, err := os.MkdirTemp("", "gopass-")
                   ^
4 issues:
* usetesting: 4
make: *** [Makefile:139: codequality] Error 1

All fixed, I believe the testing's Setenv() and TempDir() is more robust for testing and isolation.
Also there was some problems with find.go file also by codequality test. Fixed them as well.
All tests are passed.

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.

Hello @GLobyNew, 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!

Summary of Changes

This pull request addresses a deprecation warning from golangci-lint regarding the tenv linter, which is being replaced by usetesting. The author, GLobyNew, has replaced the linter in .golangci.yml and addressed the new issues that arose from using usetesting, specifically related to the use of os.Setenv() and os.MkdirTemp() in tests. These have been replaced with t.Setenv() and t.TempDir() respectively, which are considered more robust for testing and isolation. Additionally, some minor formatting issues in internal/action/find.go were fixed.

Highlights

  • Linter Replacement: The tenv linter has been replaced with usetesting in .golangci.yml to address a deprecation warning.
  • Test Improvements: Instances of os.Setenv() and os.MkdirTemp() in tests have been replaced with t.Setenv() and t.TempDir() for better test isolation and robustness in internal/updater/update_test.go, pkg/tempfile/file_test.go, and tests/tester.go.
  • Code Formatting: Minor formatting issues in internal/action/find.go have been resolved.

Changelog

  • .golangci.yml
    • Replaced the deprecated tenv linter with usetesting.
  • internal/action/find.go
    • Added a newline to fix formatting issues.
  • internal/updater/update_test.go
    • Replaced os.Setenv() with t.Setenv() in TestIsUpdateable for better test isolation on lines 51 and 66.
  • pkg/tempfile/file_test.go
    • Replaced os.MkdirTemp() with t.TempDir() in TestTempdirBase for better test isolation on line 49.
  • tests/tester.go
    • Replaced os.MkdirTemp() with t.TempDir() in newTester for better test isolation on line 73.
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.


A linter's warning, a gentle nudge,
To keep our codebase free from sludge.
From deprecated paths, we now depart,
With testing's embrace, a brand new start.

Footnotes

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

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 replaces the deprecated tenv linter with usetesting and addresses the issues it raised. The changes generally improve the testing practices by using t.Setenv() and t.TempDir(). However, there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Redundant nil return: The return nil statements in internal/updater/update_test.go are redundant because t.Setenv does not return an error. Removing them simplifies the code.
  • Unnecessary error check removal: The removal of require.NoError(t, err) in tests/tester.go and pkg/tempfile/file_test.go is concerning. While t.TempDir() handles the error internally, explicitly checking for an error provides better context and control during testing. Reintroducing the error check would enhance the robustness of the tests.
  • Code formatting: The added blank lines in internal/action/find.go do not seem to add any value and should be removed.

Merge Readiness

The pull request is almost ready for merging. Addressing the redundant return nil statements and reintroducing the error check after t.TempDir() would improve the code. The formatting in internal/action/find.go should also be corrected. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.

@GLobyNew
Copy link
Contributor Author

Commited additional checks as Gimini suggested.

Copy link
Member

@dominikschulz dominikschulz left a comment

Choose a reason for hiding this comment

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

Thanks for replacing the linter and fixing the issues. All very good improvements.

@dominikschulz dominikschulz merged commit c32ec32 into gopasspw:master Mar 14, 2025
7 of 8 checks passed
@GLobyNew GLobyNew deleted the lintIssues branch March 14, 2025 15:59
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