Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix golint failures on pkg/kubectl/cmd/completion, pkg/kubectl/cmd/cp, pkg/kubectl/cmd/edit #74250

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/kubectl/cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.")
Expand Down
5 changes: 5 additions & 0 deletions pkg/kubectl/cmd/cp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -159,13 +162,15 @@ 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)
}
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")
Expand Down
1 change: 1 addition & 0 deletions pkg/kubectl/cmd/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
44 changes: 22 additions & 22 deletions pkg/kubectl/cmd/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
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
}
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) {
Expand Down