Skip to content

Commit

Permalink
fix: update golanci-lint and fix new issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mateimicu committed Jul 18, 2022
1 parent 632a2da commit eefd1c9
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 38 deletions.
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ linters:
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
Expand All @@ -24,8 +24,10 @@ linters:
- lll
- misspell
- nakedret
- noctx
- nolintlint
- revive
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
Expand Down
2 changes: 0 additions & 2 deletions cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ func newAWSCommand() *cobra.Command {
"aws-partitions",
[]string{"aws"},
fmt.Sprintf("In what partitions to search for clusters. Supported %v", aws.AllowedParitions()))

AWSCommand.PersistentFlags().StringVar(
&kubeconfigPath,
"kubeconfig-path",
kubeconfig.GetDefaultKubeconfigPath(),
"Path to the kubeconfig to work with")

AWSCommand.PersistentFlags().StringVar(
&alias,
"context-name-alias",
Expand Down
2 changes: 1 addition & 1 deletion cmd/aws_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type tableTestCase struct {
}

var (
tableCases []tableTestCase = []tableTestCase{
tableCases = []tableTestCase{
{Clusters: cluster.GetMockClusters(0)},
{Clusters: cluster.GetMockClusters(1)},
{Clusters: cluster.GetMockClusters(3)},
Expand Down
6 changes: 3 additions & 3 deletions cmd/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type testCase struct {
Partitions []string
}

var cases []testCase = []testCase{
var cases = []testCase{
{[]string{"aws", "list"}, []string{"aws"}},
{[]string{"aws", "list"}, []string{"aws-cn"}},
{[]string{"aws", "list"}, []string{"aws-iso-b"}},
Expand Down Expand Up @@ -53,13 +53,13 @@ func TestQueryAllRegions(t *testing.T) {
defer func() { log.SetOutput(os.Stdout) }()
hook := test.NewGlobal()
defer hook.Reset()
args := append(tt.Cmd, []string{
tt.Cmd = append(tt.Cmd, []string{
"--log-level", "debug",
"--kubeconfig-path", kubeconfigPath,
"--aws-partitions", strings.Join(tt.Partitions, ","),
}...)

cmd.SetArgs(args)
cmd.SetArgs(tt.Cmd)
err = cmd.Execute()
if err != nil {
t.Error(err.Error())
Expand Down
1 change: 1 addition & 0 deletions cmd/aws_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func copy(src, dst string) error {
return err
}

// nolint: gomnd
buf := make([]byte, 1000000)
for {
n, err := source.Read(buf)
Expand Down
4 changes: 2 additions & 2 deletions cmd/aws_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_generateBackupNameNoConflict(t *testing.T) {
kubeconfigPath := filepath.Join(dir, "kubeconfig")
backupKubeconfigPath := filepath.Join(dir, "kubeconfig.bak")

if err := ioutil.WriteFile(kubeconfigPath, []byte("..."), 0666); err != nil {
if err := ioutil.WriteFile(kubeconfigPath, []byte("..."), 0600); err != nil {
t.Error(err.Error())
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func Test_fileExistsFile(t *testing.T) {

path := filepath.Join(dir, "kubeconfig")

if err := ioutil.WriteFile(path, []byte("...\n"), 0666); err != nil {
if err := ioutil.WriteFile(path, []byte("...\n"), 0600); err != nil {
t.Error(err.Error())
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"path/filepath"
"strings"

"github.com/mateimicu/kdiscover/internal/kubeconfig"
"github.com/spf13/cobra"
Expand All @@ -32,7 +32,6 @@ var (
)

func NewRootCommand(version, commit, date, commandPrefix string) *cobra.Command {

rootCmd := &cobra.Command{
Use: commandPrefix,
Short: "Discover all EKS clusters on an account.",
Expand Down
23 changes: 12 additions & 11 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
log "github.com/sirupsen/logrus"
)

// nolint:unused, varcheck, deadcode
var update = flag.Bool("update", false, "update .golden files")

var basicCommands []struct{ cmd []string } = []struct {
var basicCommands = []struct {
cmd []string
}{
{[]string{"version"}},
Expand Down Expand Up @@ -44,12 +45,12 @@ func Test_CascadingPersistPreRunEHackWithLoggingLevels(t *testing.T) {
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)

completCmd := append(tt.cmd, "--log-level")
completCmd = append(completCmd, k)
completCmd = append(completCmd, "--kubeconfig-path")
completCmd = append(completCmd, kubeconfigPath)
tt.cmd = append(tt.cmd, "--log-level")
tt.cmd = append(tt.cmd, k)
tt.cmd = append(tt.cmd, "--kubeconfig-path")
tt.cmd = append(tt.cmd, kubeconfigPath)

cmd.SetArgs(completCmd)
cmd.SetArgs(tt.cmd)
err = cmd.Execute()
if err != nil {
t.Error(err.Error())
Expand All @@ -58,11 +59,11 @@ func Test_CascadingPersistPreRunEHackWithLoggingLevels(t *testing.T) {
// none logging level is a special case
if k == "none" {
if log.StandardLogger().Out != ioutil.Discard {
t.Errorf("Running %v we were expecting logging to be discared but it is not ", completCmd)
t.Errorf("Running %v we were expecting logging to be discared but it is not ", tt.cmd)
}
} else {
if exp != log.GetLevel() {
t.Errorf("Running %v we were expecting logger to be %v but it is %v", completCmd, exp, log.GetLevel())
t.Errorf("Running %v we were expecting logger to be %v but it is %v", tt.cmd, exp, log.GetLevel())
}
}
})
Expand All @@ -82,9 +83,9 @@ func Test_HelpFunction(t *testing.T) {
cmd.SetOut(buf)
cmd.SetErr(buf)

completCmd := append(tt.cmd, "--help")
tt.cmd = append(tt.cmd, "--help")

cmd.SetArgs(completCmd)
cmd.SetArgs(tt.cmd)
err := cmd.Execute()
if err != nil {
t.Error(err.Error())
Expand All @@ -93,7 +94,7 @@ func Test_HelpFunction(t *testing.T) {
if !strings.Contains(buf.String(), expected) {
t.Errorf(
"Running %v we were expecting %v in the output but got: %v",
completCmd, expected, buf.String())
tt.cmd, expected, buf.String())
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

var (
shortened bool = false
output string = "json"
shortened = false
output = "json"
)

func newVersionCommand(version, commit, date string) *cobra.Command {
Expand Down
6 changes: 3 additions & 3 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func Test_Version(t *testing.T) {
cmd.SetOut(buf)
cmd.SetErr(buf)

completCmd := append(tt.Cmd, "--kubeconfig-path")
completCmd = append(completCmd, kubeconfigPath)
tt.Cmd = append(tt.Cmd, "--kubeconfig-path")
tt.Cmd = append(tt.Cmd, kubeconfigPath)

cmd.SetArgs(completCmd)
cmd.SetArgs(tt.Cmd)
err = cmd.Execute()
if err != nil {
t.Error(err.Error())
Expand Down
1 change: 0 additions & 1 deletion internal/aws/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
log "github.com/sirupsen/logrus"
)

//type ClusterListDescriber struct {
type EKSClient struct {
EKS eksiface.EKSAPI
Region string
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/eks_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
)

var (
options map[AuthType][]string = map[AuthType][]string{
options = map[AuthType][]string{
useAWSCLI: {"eks", "get-token", "--cluster-name"},
useIAMAuthenticator: {"token", "-i"},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/aws/eks_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ const (
)

var (
commands map[AuthType]string = map[AuthType]string{
commands = map[AuthType]string{
useAWSCLI: commandAWScli,
useIAMAuthenticator: commandIAMAuthenticator,
}

awsCLIVersionCommand []string = []string{"aws", "--version"}
awsCLIVersionCommand = []string{"aws", "--version"}
)

func getAuthType() AuthType {
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/eks_kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAWSCLIVersion(t *testing.T) {
for _, tt := range tts {
testname := fmt.Sprintf("%v -> %v (cmd %v)", tt.Output, tt.Expected, tt.SupportCommand)
t.Run(testname, func(t *testing.T) {
//overwrite command
// overwrite command
out := getAWSCLIversion([]string{tt.SupportCommand, fmt.Sprintf("'%v'", tt.Output)})

expVer, err := semver.NewVersion(tt.Expected)
Expand Down
5 changes: 3 additions & 2 deletions internal/aws/eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/assert"
)

//nolint:unused, varcheck, deadcode
var update = flag.Bool("update", false, "update .golden files")

type mockEKSClient struct {
Expand Down Expand Up @@ -50,7 +51,7 @@ func (c *mockEKSClient) ListClustersPages(_ *eks.ListClustersInput, fn func(*eks
o := eks.ListClustersOutput{}
clusters := []*string{}

//prepare clusters
// prepare clusters
for _, cls := range c.Clusters[start:end] {
clusters = append(clusters, &cls.Name)
}
Expand Down Expand Up @@ -105,7 +106,7 @@ type testCase struct {
Region string
}

var cases []testCase = []testCase{
var cases = []testCase{
// Happy flows
{
Client: mockEKSClient{
Expand Down
3 changes: 2 additions & 1 deletion internal/cluster/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
func stringWithCharset(length int, charset string) string {
b := make([]byte, length)
for i := range b {
// NOTE(mmicu): this is for testing only
// #nosec
b[i] = charset[rand.Intn(len(charset))]
}
return string(b)
Expand All @@ -27,7 +29,6 @@ func randomString(length int) string {

func dummyGenerateAuthInfo(cls *Cluster) *clientcmdapi.AuthInfo {
return clientcmdapi.NewAuthInfo()

}

func getMockClusters(i int, r string) *Cluster {
Expand Down
4 changes: 2 additions & 2 deletions internal/kubeconfig/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ func TestLoadKubeconfig(t *testing.T) {
t.Errorf("Failed to load kubeconfig %v", err.Error())
}

out := make([]simpleCluster, 0, 0)
out := make([]simpleCluster, 0)
for _, c := range clusters {
out = append(out, simpleCluster{
Endpoint: c.Endpoint,
CertificateAuthorityData: c.CertificateAuthorityData,
})
}

expected := make([]simpleCluster, 0, 0)
expected := make([]simpleCluster, 0)
for _, c := range tc.Clusters {
expected = append(expected, simpleCluster{
Endpoint: c.Endpoint,
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/mateimicu/kdiscover/cmd"
)

//nolint:unused, varcheck, deadcode
var update = flag.Bool("update", false, "update .golden files")

var (
Expand Down

0 comments on commit eefd1c9

Please sign in to comment.