From e2c1f435516085ef17f222fb7f89cd3ba13aa944 Mon Sep 17 00:00:00 2001 From: SataQiu Date: Tue, 19 Feb 2019 17:39:39 +0800 Subject: [PATCH] fix golint failures on pkg/kubectl/cmd/completion pkg/kubectl/cmd/cp pkg/kubectl/cmd/edit --- hack/.golint_failures | 3 -- pkg/kubectl/cmd/completion/completion.go | 2 ++ pkg/kubectl/cmd/cp/cp.go | 5 +++ pkg/kubectl/cmd/edit/edit.go | 1 + pkg/kubectl/cmd/edit/edit_test.go | 46 ++++++++++++------------ 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/hack/.golint_failures b/hack/.golint_failures index f7fdae8bc1..99a99825c9 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -132,15 +132,12 @@ pkg/kubectl/cmd/attach pkg/kubectl/cmd/autoscale pkg/kubectl/cmd/certificates pkg/kubectl/cmd/clusterinfo -pkg/kubectl/cmd/completion pkg/kubectl/cmd/convert -pkg/kubectl/cmd/cp pkg/kubectl/cmd/create pkg/kubectl/cmd/delete pkg/kubectl/cmd/describe pkg/kubectl/cmd/diff pkg/kubectl/cmd/drain -pkg/kubectl/cmd/edit pkg/kubectl/cmd/exec pkg/kubectl/cmd/explain pkg/kubectl/cmd/expose diff --git a/pkg/kubectl/cmd/completion/completion.go b/pkg/kubectl/cmd/completion/completion.go index 855c8306ea..db31689dfc 100644 --- a/pkg/kubectl/cmd/completion/completion.go +++ b/pkg/kubectl/cmd/completion/completion.go @@ -92,6 +92,7 @@ var ( } ) +// NewCmdCompletion creates the `completion` command func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command { shells := []string{} for s := range completionShells { @@ -114,6 +115,7 @@ func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command { return cmd } +// RunCompletion checks given arguments and executes command func RunCompletion(out io.Writer, boilerPlate string, cmd *cobra.Command, args []string) error { if len(args) == 0 { return cmdutil.UsageErrorf(cmd, "Shell not specified.") diff --git a/pkg/kubectl/cmd/cp/cp.go b/pkg/kubectl/cmd/cp/cp.go index afcf649c35..4f6c93e9a1 100644 --- a/pkg/kubectl/cmd/cp/cp.go +++ b/pkg/kubectl/cmd/cp/cp.go @@ -66,6 +66,7 @@ var ( /file/path for a local file`) ) +// CopyOptions have the data required to perform the copy operation type CopyOptions struct { Container string Namespace string @@ -77,6 +78,7 @@ type CopyOptions struct { genericclioptions.IOStreams } +// NewCopyOptions creates the options for copy func NewCopyOptions(ioStreams genericclioptions.IOStreams) *CopyOptions { return &CopyOptions{ IOStreams: ioStreams, @@ -140,6 +142,7 @@ func extractFileSpec(arg string) (fileSpec, error) { return fileSpec{}, errFileSpecDoesntMatchFormat } +// Complete completes all the required options func (o *CopyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { var err error o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace() @@ -159,6 +162,7 @@ func (o *CopyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { return nil } +// Validate makes sure provided values for CopyOptions are valid func (o *CopyOptions) Validate(cmd *cobra.Command, args []string) error { if len(args) != 2 { return cmdutil.UsageErrorf(cmd, cpUsageStr) @@ -166,6 +170,7 @@ func (o *CopyOptions) Validate(cmd *cobra.Command, args []string) error { return nil } +// Run performs the execution func (o *CopyOptions) Run(args []string) error { if len(args) < 2 { return fmt.Errorf("source and destination are required") diff --git a/pkg/kubectl/cmd/edit/edit.go b/pkg/kubectl/cmd/edit/edit.go index ab121f41ed..94fcc4fd29 100644 --- a/pkg/kubectl/cmd/edit/edit.go +++ b/pkg/kubectl/cmd/edit/edit.go @@ -67,6 +67,7 @@ var ( kubectl edit deployment/mydeployment -o yaml --save-config`)) ) +// NewCmdEdit creates the `edit` command func NewCmdEdit(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { o := editor.NewEditOptions(editor.NormalEditMode, ioStreams) o.ValidateOptions = cmdutil.ValidateOptions{EnableValidation: true} diff --git a/pkg/kubectl/cmd/edit/edit_test.go b/pkg/kubectl/cmd/edit/edit_test.go index c4dfbb5c6a..0abcc6cfa1 100644 --- a/pkg/kubectl/cmd/edit/edit_test.go +++ b/pkg/kubectl/cmd/edit/edit_test.go @@ -129,30 +129,30 @@ func TestEdit(t *testing.T) { } } return &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(resultingOutput))}, nil - } else { - if step.StepType != "request" { - t.Fatalf("%s, step %d: expected request step, got %s %s", name, i, req.Method, req.URL.Path) - } - body = tryIndent(body) - expectedInput = tryIndent(expectedInput) - if req.Method != step.RequestMethod || req.URL.Path != step.RequestPath || req.Header.Get("Content-Type") != step.RequestContentType { - t.Fatalf( - "%s, step %d: expected \n%s %s (content-type=%s)\ngot\n%s %s (content-type=%s)", name, i, - step.RequestMethod, step.RequestPath, step.RequestContentType, - req.Method, req.URL.Path, req.Header.Get("Content-Type"), - ) - } - if !bytes.Equal(body, expectedInput) { - if updateInputFixtures { - // Convenience to allow recapturing the input and persisting it here - ioutil.WriteFile(inputFile, body, os.FileMode(0644)) - } else { - t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput))) - t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar) - } - } - return &http.Response{StatusCode: step.ResponseStatusCode, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(resultingOutput))}, nil } + if step.StepType != "request" { + t.Fatalf("%s, step %d: expected request step, got %s %s", name, i, req.Method, req.URL.Path) + } + body = tryIndent(body) + expectedInput = tryIndent(expectedInput) + if req.Method != step.RequestMethod || req.URL.Path != step.RequestPath || req.Header.Get("Content-Type") != step.RequestContentType { + t.Fatalf( + "%s, step %d: expected \n%s %s (content-type=%s)\ngot\n%s %s (content-type=%s)", name, i, + step.RequestMethod, step.RequestPath, step.RequestContentType, + req.Method, req.URL.Path, req.Header.Get("Content-Type"), + ) + } + if !bytes.Equal(body, expectedInput) { + if updateInputFixtures { + // Convenience to allow recapturing the input and persisting it here + ioutil.WriteFile(inputFile, body, os.FileMode(0644)) + } else { + t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput))) + t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar) + } + } + return &http.Response{StatusCode: step.ResponseStatusCode, Header: cmdtesting.DefaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(resultingOutput))}, nil + } handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {