mirror of https://github.com/k3s-io/k3s
Merge pull request #74250 from SataQiu/fix-golint-20190219
Fix golint failures on pkg/kubectl/cmd/completion, pkg/kubectl/cmd/cp, pkg/kubectl/cmd/editpull/564/head
commit
651faf2e0d
|
@ -131,15 +131,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
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue