fix lint errors (#388)

* fix typo (misspell)

* ineffectual assignment to err (ineffassign)

* if block ends with a return statement, so drop this else and outdent its block (golint)

* should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (golint)

* struct field LogHttp should be LogHTTP (golint)

* fix last typo
This commit is contained in:
Toshinori Sugita 2019-08-25 14:46:13 +09:00 committed by Knative Prow Robot
parent 04a55b27f2
commit 699ac5e7cb
17 changed files with 30 additions and 28 deletions

View File

@ -63,7 +63,7 @@ func TestGetNamespaceDefault(t *testing.T) {
}
// test with all-namespaces flag set with sample namespace
// all-namespaces flag takes the precendence
// all-namespaces flag takes the precedence
func TestGetNamespaceAllNamespacesSet(t *testing.T) {
testCmd := testCommandGenerator(true)
expectedNamespace := ""
@ -86,7 +86,7 @@ func TestGetNamespaceAllNamespacesSet(t *testing.T) {
}
// test with all-namespace flag set without any namespace flag set
// all-namespace flag takes precendence
// all-namespace flag takes precedence
func TestGetNamespaceDefaultAllNamespacesUnset(t *testing.T) {
testCmd := testCommandGenerator(true)
expectedNamespace := ""

View File

@ -137,7 +137,7 @@ func TestPluginHandler(t *testing.T) {
})
t.Run("HandlePluginCommand", func(t *testing.T) {
t.Run("sucess handling", func(t *testing.T) {
t.Run("success handling", func(t *testing.T) {
setup(t)
defer cleanup(t)
beforeEach(t)

View File

@ -212,6 +212,7 @@ func TestPluginList(t *testing.T) {
defer ctx.cleanup()
err := ctx.createTestPlugin(KnTestPluginName, FileModeExecutable, false)
assert.NilError(t, err)
err = ctx.execute("plugin", "list")
assert.NilError(t, err)

View File

@ -33,7 +33,7 @@ import (
"github.com/spf13/cobra"
)
// pluginVerifier verifies that existing kn commands are not overriden
// pluginVerifier verifies that existing kn commands are not overridden
type pluginVerifier struct {
root *cobra.Command
seenPlugins map[string]string

View File

@ -29,7 +29,7 @@ import (
"github.com/spf13/cobra"
)
// pluginVerifier verifies that existing kn commands are not overriden
// pluginVerifier verifies that existing kn commands are not overridden
type pluginVerifier struct {
root *cobra.Command
seenPlugins map[string]string

View File

@ -173,6 +173,9 @@ func TestServiceCreateEnv(t *testing.T) {
}
template, err := servinglib.RevisionTemplateOfService(created)
if err != nil {
t.Fatal(err)
}
actualEnvVars, err := servinglib.EnvToMap(template.Spec.Containers[0].Env)
if err != nil {
t.Fatal(err)
@ -453,10 +456,10 @@ func TestServiceCreateEnvForce(t *testing.T) {
"B": "LIONS"}
template, err := servinglib.RevisionTemplateOfService(created)
actualEnvVars, err := servinglib.EnvToMap(template.Spec.Containers[0].Env)
if err != nil {
t.Fatal(err)
}
actualEnvVars, err := servinglib.EnvToMap(template.Spec.Containers[0].Env)
if err != nil {
t.Fatal(err)
} else if template.Spec.Containers[0].Image != "gcr.io/foo/bar:v2" {

View File

@ -145,6 +145,9 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
}
revisionDescs, err := getRevisionDescriptions(client, service, printDetails)
if err != nil {
return err
}
return describe(cmd.OutOrStdout(), service, revisionDescs)
},

View File

@ -127,7 +127,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
func preCheck(cmd *cobra.Command, args []string) error {
if cmd.Flags().NFlag() == 0 {
return errors.New(fmt.Sprintf("flag(s) not set\nUsage: %s", cmd.Use))
return fmt.Errorf("flag(s) not set\nUsage: %s", cmd.Use)
}
return nil

View File

@ -15,7 +15,6 @@
package commands
import (
"errors"
"fmt"
"io"
"os"
@ -47,7 +46,7 @@ type KnParams struct {
NewClient func(namespace string) (serving_kn_v1alpha1.KnClient, error)
// General global options
LogHttp bool
LogHTTP bool
// Set this if you want to nail down the namespace
fixedCurrentNamespace string
@ -82,7 +81,7 @@ func (params *KnParams) GetConfig() (serving_v1alpha1_client.ServingV1alpha1Inte
if err != nil {
return nil, err
}
if params.LogHttp {
if params.LogHTTP {
// TODO: When we update to the newer version of client-go, replace with
// config.Wrap() for future compat.
config.WrapTransport = util.NewLoggingTransport
@ -110,9 +109,8 @@ func (params *KnParams) GetClientConfig() (clientcmd.ClientConfig, error) {
paths := filepath.SplitList(params.KubeCfgPath)
if len(paths) > 1 {
return nil, errors.New(fmt.Sprintf("Can not find config file. '%s' looks like a path. "+
"Please use the env var KUBECONFIG if you want to check for multiple configuration files", params.KubeCfgPath))
} else {
return nil, errors.New(fmt.Sprintf("Config file '%s' can not be found", params.KubeCfgPath))
return nil, fmt.Errorf("Can not find config file. '%s' looks like a path. "+
"Please use the env var KUBECONFIG if you want to check for multiple configuration files", params.KubeCfgPath)
}
return nil, fmt.Errorf("Config file '%s' can not be found", params.KubeCfgPath)
}

View File

@ -77,7 +77,7 @@ func TestGetConfig(t *testing.T) {
} {
p := &KnParams{
ClientConfig: tc.clientConfig,
LogHttp: tc.logHttp,
LogHTTP: tc.logHttp,
}
_, err := p.GetConfig()

View File

@ -15,7 +15,6 @@
package core
import (
"errors"
"flag"
"fmt"
"io"
@ -130,7 +129,7 @@ func NewKnCommand(params ...commands.KnParams) *cobra.Command {
// Persistent flags
rootCmd.PersistentFlags().StringVar(&commands.CfgFile, "config", "", "kn config file (default is $HOME/.kn/config.yaml)")
rootCmd.PersistentFlags().StringVar(&p.KubeCfgPath, "kubeconfig", "", "kubectl config file (default is $HOME/.kube/config)")
flags.AddBothBoolFlags(rootCmd.PersistentFlags(), &p.LogHttp, "log-http", "", false, "log http traffic")
flags.AddBothBoolFlags(rootCmd.PersistentFlags(), &p.LogHTTP, "log-http", "", false, "log http traffic")
plugin.AddPluginFlags(rootCmd)
plugin.BindPluginsFlagToViper(rootCmd)
@ -175,10 +174,9 @@ func EmptyAndUnknownSubCommands(cmd *cobra.Command) {
fmt.Println()
if len(args) == 0 {
return errors.New(fmt.Sprintf("please provide a valid sub-command for \"kn %s\"", aCmd.Name()))
} else {
return errors.New(fmt.Sprintf("unknown sub-command \"%s\" for \"kn %s\"", args[0], aCmd.Name()))
return fmt.Errorf("please provide a valid sub-command for \"kn %s\"", aCmd.Name())
}
return fmt.Errorf("unknown sub-command \"%s\" for \"kn %s\"", args[0], aCmd.Name())
}
}

View File

@ -240,9 +240,8 @@ func verifyInputSanity(trafficFlags *flags.Traffic) error {
// To check if there are duplicate revision names in traffic flags
if _, exist := revisionRefMap[revisionRef]; exist {
return errorRepeatingRevision("--traffic", revisionRef)
} else {
revisionRefMap[revisionRef] = i
}
revisionRefMap[revisionRef] = i
percentInt, err := strconv.Atoi(percent)
if err != nil {

View File

@ -15,7 +15,6 @@
package serving
import (
"errors"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
@ -44,5 +43,5 @@ func GetGroupVersionKind(obj runtime.Object, gv schema.GroupVersion) (*schema.Gr
return &gvk, nil
}
}
return nil, errors.New(fmt.Sprintf("no group version %s registered in %s", gv, scheme.Scheme.Name()))
return nil, fmt.Errorf("no group version %s registered in %s", gv, scheme.Scheme.Name())
}

View File

@ -37,9 +37,8 @@ func mapFromArray(arr []string, delimiter string, allowSingles bool) (map[string
if len(pairSlice) <= 1 {
if len(pairSlice) == 0 || !allowSingles {
return nil, fmt.Errorf("Argument requires a value that contains the %q character; got %q", delimiter, pairStr)
} else {
returnMap[pairSlice[0]] = ""
}
returnMap[pairSlice[0]] = ""
} else {
returnMap[pairSlice[0]] = pairSlice[1]
}

View File

@ -57,7 +57,7 @@ func NewE2eTest(t *testing.T) *e2eTest {
}
}
// Setup set up an enviroment for kn integration test returns the Teardown cleanup function
// Setup set up an environment for kn integration test returns the Teardown cleanup function
func (test *e2eTest) Setup(t *testing.T) {
test.env.Namespace = fmt.Sprintf("%s%d", test.env.Namespace, getNamespaceCountAndIncrement())
test.kn = kn{t, test.env.Namespace, Logger{}}

View File

@ -47,6 +47,7 @@ func TestService(t *testing.T) {
func (test *e2eTest) serviceCreateDuplicate(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
assert.NilError(t, err)
assert.Check(t, strings.Contains(out, serviceName), "The service does not exist yet")
_, err = test.kn.RunWithOpts([]string{"service", "create", serviceName,
@ -65,6 +66,7 @@ func (test *e2eTest) serviceDescribeWithPrintFlags(t *testing.T, serviceName str
func (test *e2eTest) serviceDeleteNonexistent(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
assert.NilError(t, err)
assert.Check(t, !strings.Contains(out, serviceName), "The service exists")
_, err = test.kn.RunWithOpts([]string{"service", "delete", serviceName}, runOpts{NoNamespace: false, AllowError: true})

View File

@ -223,7 +223,7 @@ func TestTrafficSplit(t *testing.T) {
},
)
// test reducing number of targets from traffic blockdd
t.Run("remove a revision with tag old from traffic block entierly",
t.Run("remove a revision with tag old from traffic block entirely",
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)