Skip to content

Commit

Permalink
Merge pull request #10689 from sivchari/add-tenv
Browse files Browse the repository at this point in the history
🐛 Add tenv linter
  • Loading branch information
k8s-ci-robot authored May 30, 2024
2 parents f6f58a4 + 687113b commit 0539a29
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ linters:
- rowserrcheck
- staticcheck
- stylecheck
- tenv
- thelper
- typecheck
- unconvert
Expand Down
18 changes: 6 additions & 12 deletions cmd/clusterctl/client/config/reader_viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ 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())
defer os.RemoveAll(dir)
dir := t.TempDir()

_ = 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())
Expand Down Expand Up @@ -195,11 +193,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())
Expand All @@ -213,11 +209,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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
package main

import (
"os"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
})
}
}

0 comments on commit 0539a29

Please sign in to comment.