From 9b3c639a453c0d2581889943f7c7ec4c0f2a6ccf Mon Sep 17 00:00:00 2001 From: sivchari Date: Tue, 28 May 2024 18:26:31 +0900 Subject: [PATCH 1/4] add: tenv linter Signed-off-by: sivchari --- .golangci.yml | 1 + .../client/config/reader_viper_test.go | 17 ++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 812acedab788..85720606a6db 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -51,6 +51,7 @@ linters: - rowserrcheck - staticcheck - stylecheck + - tenv - thelper - typecheck - unconvert diff --git a/cmd/clusterctl/client/config/reader_viper_test.go b/cmd/clusterctl/client/config/reader_viper_test.go index b5f675416177..81e0c6456963 100644 --- a/cmd/clusterctl/client/config/reader_viper_test.go +++ b/cmd/clusterctl/client/config/reader_viper_test.go @@ -125,11 +125,10 @@ func Test_viperReader_Init(t *testing.T) { func Test_viperReader_Get(t *testing.T) { g := NewWithT(t) - dir, err := os.MkdirTemp("", "clusterctl") - g.Expect(err).ToNot(HaveOccurred()) + dir := t.TempDir() defer os.RemoveAll(dir) - _ = os.Setenv("FOO", "foo") + t.Setenv("FOO", "foo") configFile := filepath.Join(dir, "clusterctl.yaml") g.Expect(os.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) @@ -195,11 +194,9 @@ func Test_viperReader_GetWithoutDefaultConfig(t *testing.T) { ctx := context.Background() - dir, err := os.MkdirTemp("", "clusterctl") - g.Expect(err).ToNot(HaveOccurred()) - defer os.RemoveAll(dir) + dir := t.TempDir() - _ = os.Setenv("FOO_FOO", "bar") + t.Setenv("FOO_FOO", "bar") v, err := newViperReader(injectConfigPaths([]string{dir})) g.Expect(err).ToNot(HaveOccurred()) @@ -213,11 +210,9 @@ func Test_viperReader_GetWithoutDefaultConfig(t *testing.T) { func Test_viperReader_Set(t *testing.T) { g := NewWithT(t) - dir, err := os.MkdirTemp("", "clusterctl") - g.Expect(err).ToNot(HaveOccurred()) - defer os.RemoveAll(dir) + dir := t.TempDir() - _ = os.Setenv("FOO", "foo") + t.Setenv("FOO", "foo") configFile := filepath.Join(dir, "clusterctl.yaml") From 509a1b149d4555d9eeae16e0f3c771a4184c35be Mon Sep 17 00:00:00 2001 From: sivchari Date: Tue, 28 May 2024 18:27:25 +0900 Subject: [PATCH 2/4] run: go fmt Signed-off-by: sivchari --- cmd/clusterctl/client/config/reader_viper_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/clusterctl/client/config/reader_viper_test.go b/cmd/clusterctl/client/config/reader_viper_test.go index 81e0c6456963..326c22339044 100644 --- a/cmd/clusterctl/client/config/reader_viper_test.go +++ b/cmd/clusterctl/client/config/reader_viper_test.go @@ -125,10 +125,10 @@ func Test_viperReader_Init(t *testing.T) { func Test_viperReader_Get(t *testing.T) { g := NewWithT(t) - dir := t.TempDir() + dir := t.TempDir() defer os.RemoveAll(dir) - t.Setenv("FOO", "foo") + t.Setenv("FOO", "foo") configFile := filepath.Join(dir, "clusterctl.yaml") g.Expect(os.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) @@ -194,7 +194,7 @@ func Test_viperReader_GetWithoutDefaultConfig(t *testing.T) { ctx := context.Background() - dir := t.TempDir() + dir := t.TempDir() t.Setenv("FOO_FOO", "bar") @@ -210,7 +210,7 @@ func Test_viperReader_GetWithoutDefaultConfig(t *testing.T) { func Test_viperReader_Set(t *testing.T) { g := NewWithT(t) - dir := t.TempDir() + dir := t.TempDir() t.Setenv("FOO", "foo") From 88c37d57591c851e8ae581f808d02adca96000a6 Mon Sep 17 00:00:00 2001 From: sivchari Date: Tue, 28 May 2024 18:38:16 +0900 Subject: [PATCH 3/4] re-run golangci-lint Signed-off-by: sivchari --- .../internal/update_providers/provider_issues_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hack/tools/release/internal/update_providers/provider_issues_test.go b/hack/tools/release/internal/update_providers/provider_issues_test.go index 4e40aa4ed344..8629f3e6a238 100644 --- a/hack/tools/release/internal/update_providers/provider_issues_test.go +++ b/hack/tools/release/internal/update_providers/provider_issues_test.go @@ -20,7 +20,6 @@ limitations under the License. package main import ( - "os" "testing" . "github.com/onsi/gomega" @@ -96,8 +95,8 @@ func Test_GetReleaseDetails(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - _ = os.Setenv("RELEASE_TAG", tt.releaseTag) - _ = os.Setenv("RELEASE_DATE", tt.releaseDate) + t.Setenv("RELEASE_TAG", tt.releaseTag) + t.Setenv("RELEASE_DATE", tt.releaseDate) got, err := getReleaseDetails() if tt.expectErr { @@ -108,8 +107,6 @@ func Test_GetReleaseDetails(t *testing.T) { g.Expect(got.BetaTag).To(Equal(tt.want.BetaTag)) g.Expect(got.ReleaseLink).To(Equal(tt.want.ReleaseLink)) } - _ = os.Unsetenv("RELEASE_TAG") - _ = os.Unsetenv("RELEASE_DATE") }) } } From 687113bb94eb4f554260c4bc44e384a294959a6d Mon Sep 17 00:00:00 2001 From: sivchari Date: Thu, 30 May 2024 10:33:08 +0900 Subject: [PATCH 4/4] delete unnecessary defer Remove.All() Signed-off-by: sivchari --- cmd/clusterctl/client/config/reader_viper_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/clusterctl/client/config/reader_viper_test.go b/cmd/clusterctl/client/config/reader_viper_test.go index 326c22339044..aca8f9af4d89 100644 --- a/cmd/clusterctl/client/config/reader_viper_test.go +++ b/cmd/clusterctl/client/config/reader_viper_test.go @@ -126,7 +126,6 @@ func Test_viperReader_Get(t *testing.T) { g := NewWithT(t) dir := t.TempDir() - defer os.RemoveAll(dir) t.Setenv("FOO", "foo")