Skip to content

Commit

Permalink
Merge pull request #18774 from mmorel-35/golangci-lint/tenv
Browse files Browse the repository at this point in the history
fix: enable tenv linter
  • Loading branch information
serathius authored Oct 24, 2024
2 parents 3fd35fc + 048fd57 commit c2261ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
11 changes: 3 additions & 8 deletions pkg/flags/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package flags

import (
"flag"
"os"
"strings"
"testing"

Expand All @@ -30,9 +29,8 @@ func TestSetFlagsFromEnv(t *testing.T) {
fs.String("c", "", "")
fs.Parse([]string{})

os.Clearenv()
// flags should be settable using env vars
os.Setenv("ETCD_A", "foo")
t.Setenv("ETCD_A", "foo")
// and command-line flags
if err := fs.Set("b", "bar"); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -67,7 +65,7 @@ func TestSetFlagsFromEnvBad(t *testing.T) {
// now verify that an error is propagated
fs := flag.NewFlagSet("testing", flag.ExitOnError)
fs.Int("x", 0, "")
os.Setenv("ETCD_X", "not_a_number")
t.Setenv("ETCD_X", "not_a_number")
if err := SetFlagsFromEnv(zaptest.NewLogger(t), "ETCD", fs); err == nil {
t.Errorf("err=nil, want != nil")
}
Expand All @@ -78,10 +76,7 @@ func TestSetFlagsFromEnvParsingError(t *testing.T) {
var tickMs uint
fs.UintVar(&tickMs, "heartbeat-interval", 0, "Time (in milliseconds) of a heartbeat interval.")

if oerr := os.Setenv("ETCD_HEARTBEAT_INTERVAL", "100 # ms"); oerr != nil {
t.Fatal(oerr)
}
defer os.Unsetenv("ETCD_HEARTBEAT_INTERVAL")
t.Setenv("ETCD_HEARTBEAT_INTERVAL", "100 # ms")

err := SetFlagsFromEnv(zaptest.NewLogger(t), "ETCD", fs)
for _, v := range []string{"invalid syntax", "parse error"} {
Expand Down
1 change: 1 addition & 0 deletions tools/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ linters:
- revive
- staticcheck
- stylecheck
- tenv
- testifylint
- unconvert # Remove unnecessary type conversions
- unparam
Expand Down

0 comments on commit c2261ef

Please sign in to comment.