Merge pull request #10575 from hickeyma/chore/replace-golint

chore (lint): Replace golint with revive
pull/10581/head
Martin Hickey 3 years ago committed by GitHub
commit dff9ade9d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,7 +13,7 @@ jobs:
environment: environment:
GOCACHE: "/tmp/go/cache" GOCACHE: "/tmp/go/cache"
GOLANGCI_LINT_VERSION: "1.36.0" GOLANGCI_LINT_VERSION: "1.43.0"
steps: steps:
- checkout - checkout

@ -8,12 +8,12 @@ linters:
- dupl - dupl
- gofmt - gofmt
- goimports - goimports
- golint
- gosimple - gosimple
- govet - govet
- ineffassign - ineffassign
- misspell - misspell
- nakedret - nakedret
- revive
- structcheck - structcheck
- unused - unused
- varcheck - varcheck

@ -47,10 +47,10 @@ func checkFileCompletion(t *testing.T, cmdName string, shouldBePerformed bool) {
} }
if !strings.Contains(out, "ShellCompDirectiveNoFileComp") != shouldBePerformed { if !strings.Contains(out, "ShellCompDirectiveNoFileComp") != shouldBePerformed {
if shouldBePerformed { if shouldBePerformed {
t.Error(fmt.Sprintf("Unexpected directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)) t.Errorf("Unexpected directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)
} else { } else {
t.Error(fmt.Sprintf("Did not receive directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)) t.Errorf("Did not receive directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)
} }
t.Log(out) t.Log(out)
} }

@ -313,7 +313,7 @@ func loadFile(path string) (*pluginCommand, error) {
cmds := new(pluginCommand) cmds := new(pluginCommand)
b, err := ioutil.ReadFile(path) b, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
return cmds, errors.New(fmt.Sprintf("File (%s) not provided by plugin. No plugin auto-completion possible.", path)) return cmds, fmt.Errorf("file (%s) not provided by plugin. No plugin auto-completion possible", path)
} }
err = yaml.Unmarshal(b, cmds) err = yaml.Unmarshal(b, cmds)

@ -133,8 +133,8 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdate
wg.Wait() wg.Wait()
if len(repoFailList) > 0 && failOnRepoUpdateFail { if len(repoFailList) > 0 && failOnRepoUpdateFail {
return errors.New(fmt.Sprintf("Failed to update the following repositories: %s", return fmt.Errorf("Failed to update the following repositories: %s",
repoFailList)) repoFailList)
} }
fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈") fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈")

@ -40,15 +40,15 @@ var (
errMissingName = errors.New("no name provided") errMissingName = errors.New("no name provided")
// errInvalidName indicates that an invalid release name was provided // errInvalidName indicates that an invalid release name was provided
errInvalidName = errors.New(fmt.Sprintf( errInvalidName = fmt.Errorf(
"invalid release name, must match regex %s and the length must not be longer than 53", "invalid release name, must match regex %s and the length must not be longer than 53",
validName.String())) validName.String())
// errInvalidKubernetesName indicates that the name does not meet the Kubernetes // errInvalidKubernetesName indicates that the name does not meet the Kubernetes
// restrictions on metadata names. // restrictions on metadata names.
errInvalidKubernetesName = errors.New(fmt.Sprintf( errInvalidKubernetesName = fmt.Errorf(
"invalid metadata name, must match regex %s and the length must not be longer than 253", "invalid metadata name, must match regex %s and the length must not be longer than 253",
validName.String())) validName.String())
) )
const ( const (

@ -51,9 +51,9 @@ func TestEnvSettings(t *testing.T) {
ns, kcontext string ns, kcontext string
debug bool debug bool
maxhistory int maxhistory int
kAsUser string kubeAsUser string
kAsGroups []string kubeAsGroups []string
kCaFile string kubeCaFile string
}{ }{
{ {
name: "defaults", name: "defaults",
@ -61,35 +61,35 @@ func TestEnvSettings(t *testing.T) {
maxhistory: defaultMaxHistory, maxhistory: defaultMaxHistory,
}, },
{ {
name: "with flags set", name: "with flags set",
args: "--debug --namespace=myns --kube-as-user=poro --kube-as-group=admins --kube-as-group=teatime --kube-as-group=snackeaters --kube-ca-file=/tmp/ca.crt", args: "--debug --namespace=myns --kube-as-user=poro --kube-as-group=admins --kube-as-group=teatime --kube-as-group=snackeaters --kube-ca-file=/tmp/ca.crt",
ns: "myns", ns: "myns",
debug: true, debug: true,
maxhistory: defaultMaxHistory, maxhistory: defaultMaxHistory,
kAsUser: "poro", kubeAsUser: "poro",
kAsGroups: []string{"admins", "teatime", "snackeaters"}, kubeAsGroups: []string{"admins", "teatime", "snackeaters"},
kCaFile: "/tmp/ca.crt", kubeCaFile: "/tmp/ca.crt",
}, },
{ {
name: "with envvars set", name: "with envvars set",
envvars: map[string]string{"HELM_DEBUG": "1", "HELM_NAMESPACE": "yourns", "HELM_KUBEASUSER": "pikachu", "HELM_KUBEASGROUPS": ",,,operators,snackeaters,partyanimals", "HELM_MAX_HISTORY": "5", "HELM_KUBECAFILE": "/tmp/ca.crt"}, envvars: map[string]string{"HELM_DEBUG": "1", "HELM_NAMESPACE": "yourns", "HELM_KUBEASUSER": "pikachu", "HELM_KUBEASGROUPS": ",,,operators,snackeaters,partyanimals", "HELM_MAX_HISTORY": "5", "HELM_KUBECAFILE": "/tmp/ca.crt"},
ns: "yourns", ns: "yourns",
maxhistory: 5, maxhistory: 5,
debug: true, debug: true,
kAsUser: "pikachu", kubeAsUser: "pikachu",
kAsGroups: []string{"operators", "snackeaters", "partyanimals"}, kubeAsGroups: []string{"operators", "snackeaters", "partyanimals"},
kCaFile: "/tmp/ca.crt", kubeCaFile: "/tmp/ca.crt",
}, },
{ {
name: "with flags and envvars set", name: "with flags and envvars set",
args: "--debug --namespace=myns --kube-as-user=poro --kube-as-group=admins --kube-as-group=teatime --kube-as-group=snackeaters --kube-ca-file=/my/ca.crt", args: "--debug --namespace=myns --kube-as-user=poro --kube-as-group=admins --kube-as-group=teatime --kube-as-group=snackeaters --kube-ca-file=/my/ca.crt",
envvars: map[string]string{"HELM_DEBUG": "1", "HELM_NAMESPACE": "yourns", "HELM_KUBEASUSER": "pikachu", "HELM_KUBEASGROUPS": ",,,operators,snackeaters,partyanimals", "HELM_MAX_HISTORY": "5", "HELM_KUBECAFILE": "/tmp/ca.crt"}, envvars: map[string]string{"HELM_DEBUG": "1", "HELM_NAMESPACE": "yourns", "HELM_KUBEASUSER": "pikachu", "HELM_KUBEASGROUPS": ",,,operators,snackeaters,partyanimals", "HELM_MAX_HISTORY": "5", "HELM_KUBECAFILE": "/tmp/ca.crt"},
ns: "myns", ns: "myns",
debug: true, debug: true,
maxhistory: 5, maxhistory: 5,
kAsUser: "poro", kubeAsUser: "poro",
kAsGroups: []string{"admins", "teatime", "snackeaters"}, kubeAsGroups: []string{"admins", "teatime", "snackeaters"},
kCaFile: "/my/ca.crt", kubeCaFile: "/my/ca.crt",
}, },
} }
@ -119,14 +119,14 @@ func TestEnvSettings(t *testing.T) {
if settings.MaxHistory != tt.maxhistory { if settings.MaxHistory != tt.maxhistory {
t.Errorf("expected maxHistory %d, got %d", tt.maxhistory, settings.MaxHistory) t.Errorf("expected maxHistory %d, got %d", tt.maxhistory, settings.MaxHistory)
} }
if tt.kAsUser != settings.KubeAsUser { if tt.kubeAsUser != settings.KubeAsUser {
t.Errorf("expected kAsUser %q, got %q", tt.kAsUser, settings.KubeAsUser) t.Errorf("expected kAsUser %q, got %q", tt.kubeAsUser, settings.KubeAsUser)
} }
if !reflect.DeepEqual(tt.kAsGroups, settings.KubeAsGroups) { if !reflect.DeepEqual(tt.kubeAsGroups, settings.KubeAsGroups) {
t.Errorf("expected kAsGroups %+v, got %+v", len(tt.kAsGroups), len(settings.KubeAsGroups)) t.Errorf("expected kAsGroups %+v, got %+v", len(tt.kubeAsGroups), len(settings.KubeAsGroups))
} }
if tt.kCaFile != settings.KubeCaFile { if tt.kubeCaFile != settings.KubeCaFile {
t.Errorf("expected kCaFile %q, got %q", tt.kCaFile, settings.KubeCaFile) t.Errorf("expected kCaFile %q, got %q", tt.kubeCaFile, settings.KubeCaFile)
} }
}) })
} }

@ -296,9 +296,8 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
numDescriptors := len(descriptors) numDescriptors := len(descriptors)
if numDescriptors < minNumDescriptors { if numDescriptors < minNumDescriptors {
return nil, errors.New( return nil, fmt.Errorf("manifest does not contain minimum number of descriptors (%d), descriptors found: %d",
fmt.Sprintf("manifest does not contain minimum number of descriptors (%d), descriptors found: %d", minNumDescriptors, numDescriptors)
minNumDescriptors, numDescriptors))
} }
var configDescriptor *ocispec.Descriptor var configDescriptor *ocispec.Descriptor
var chartDescriptor *ocispec.Descriptor var chartDescriptor *ocispec.Descriptor
@ -318,22 +317,19 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
} }
} }
if configDescriptor == nil { if configDescriptor == nil {
return nil, errors.New( return nil, fmt.Errorf("could not load config with mediatype %s", ConfigMediaType)
fmt.Sprintf("could not load config with mediatype %s", ConfigMediaType))
} }
if operation.withChart && chartDescriptor == nil { if operation.withChart && chartDescriptor == nil {
return nil, errors.New( return nil, fmt.Errorf("manifest does not contain a layer with mediatype %s",
fmt.Sprintf("manifest does not contain a layer with mediatype %s", ChartLayerMediaType)
ChartLayerMediaType))
} }
var provMissing bool var provMissing bool
if operation.withProv && provDescriptor == nil { if operation.withProv && provDescriptor == nil {
if operation.ignoreMissingProv { if operation.ignoreMissingProv {
provMissing = true provMissing = true
} else { } else {
return nil, errors.New( return nil, fmt.Errorf("manifest does not contain a layer with mediatype %s",
fmt.Sprintf("manifest does not contain a layer with mediatype %s", ProvLayerMediaType)
ProvLayerMediaType))
} }
} }
result := &PullResult{ result := &PullResult{

@ -46,7 +46,7 @@ func (c *ChartUploader) UploadTo(ref, remote string) error {
} }
if u.Scheme == "" { if u.Scheme == "" {
return errors.New(fmt.Sprintf("scheme prefix missing from remote (e.g. \"%s://\")", registry.OCIScheme)) return fmt.Errorf("scheme prefix missing from remote (e.g. \"%s://\")", registry.OCIScheme)
} }
p, err := c.Pushers.ByScheme(u.Scheme) p, err := c.Pushers.ByScheme(u.Scheme)

Loading…
Cancel
Save