Skip to content

Commit

Permalink
Upgrade spf13/cobra to v1.1.1 to fix zsh completion issue (#2813)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysam12345 committed Nov 12, 2020
1 parent 9432266 commit 285f53e
Show file tree
Hide file tree
Showing 29 changed files with 376 additions and 216 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -40,7 +40,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/russross/blackfriday/v2 v2.0.1
github.com/spf13/afero v1.2.2
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.3
Expand Down
70 changes: 70 additions & 0 deletions go.sum

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions pkg/ctl/completion/completion_test.go
Expand Up @@ -2,6 +2,7 @@ package completion

import (
"bytes"
"errors"
"fmt"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -38,10 +39,10 @@ var _ = Describe("completion", func() {

It("with invalid shell", func() {
cmd := newMockCmd("invalid-shell")
out, err := cmd.execute()
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("unknown command \"invalid-shell\" for \"completion\""))
Expect(out).To(ContainSubstring("usage"))
Expect(err.Error()).To(ContainSubstring("Error: unknown command \"invalid-shell\" for \"completion\""))
Expect(err.Error()).To(ContainSubstring("usage"))
})

It("with no shell", func() {
Expand Down Expand Up @@ -73,8 +74,13 @@ type mockVerbCmd struct {
}

func (c mockVerbCmd) execute() (string, error) {
buf := new(bytes.Buffer)
c.parentCmd.SetOut(buf)
outBuf := new(bytes.Buffer)
errBuf := new(bytes.Buffer)
c.parentCmd.SetOut(outBuf)
c.parentCmd.SetErr(errBuf)
err := c.parentCmd.Execute()
return buf.String(), err
if err != nil {
err = errors.New(errBuf.String())
}
return outBuf.String(), err
}
14 changes: 7 additions & 7 deletions pkg/ctl/create/cluster_test.go
Expand Up @@ -89,15 +89,15 @@ var _ = Describe("create cluster", func() {
cmd := newDefaultCmd(commandArgs...)
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(c.error.Error()))
Expect(err.Error()).To(ContainSubstring(c.error.Error()))
},
Entry("with cluster name as argument and flag", invalidParamsCase{
args: []string{"clusterName", "--name", "clusterName"},
error: fmt.Errorf("--name=clusterName and argument clusterName cannot be used at the same time"),
error: fmt.Errorf("Error: --name=clusterName and argument clusterName cannot be used at the same time"),
}),
Entry("with invalid flags", invalidParamsCase{
args: []string{"cluster", "--invalid", "dummy"},
error: fmt.Errorf("unknown flag: --invalid"),
error: fmt.Errorf("Error: unknown flag: --invalid"),
}),
)
})
Expand Down Expand Up @@ -159,7 +159,7 @@ var _ = Describe("create cluster", func() {
cmd := newDefaultCmd(commandArgs...)
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(fmt.Errorf("%s is not supported for Managed Nodegroups (--managed=true)", args[0])))
Expect(err.Error()).To(ContainSubstring(fmt.Errorf("Error: %s is not supported for Managed Nodegroups (--managed=true)", args[0]).Error()))
},
Entry("node-volume-type", "--node-volume-type", "gp2"),
Entry("max-pods-per-node", "--max-pods-per-node", "2"),
Expand All @@ -173,15 +173,15 @@ var _ = Describe("create cluster", func() {
cmd := newDefaultCmd(commandArgs...)
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(c.error.Error()))
Expect(err.Error()).To(ContainSubstring(c.error.Error()))
},
Entry("with cluster name as argument and flag", invalidParamsCase{
args: []string{"clusterName", "--name", "clusterName"},
error: fmt.Errorf("--name=clusterName and argument clusterName cannot be used at the same time"),
error: fmt.Errorf("Error: --name=clusterName and argument clusterName cannot be used at the same time"),
}),
Entry("with invalid flags", invalidParamsCase{
args: []string{"cluster", "--invalid", "dummy"},
error: fmt.Errorf("unknown flag: --invalid"),
error: fmt.Errorf("Error: unknown flag: --invalid"),
}),
)
})
Expand Down
30 changes: 18 additions & 12 deletions pkg/ctl/create/create_test.go
Expand Up @@ -5,6 +5,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
)
Expand All @@ -13,24 +14,24 @@ var _ = Describe("create", func() {
Describe("invalid-resource", func() {
It("with no flag", func() {
cmd := newDefaultCmd("invalid-resource")
out, err := cmd.execute()
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("unknown command \"invalid-resource\" for \"create\""))
Expect(out).To(ContainSubstring("usage"))
Expect(err.Error()).To(ContainSubstring("Error: unknown command \"invalid-resource\" for \"create\""))
Expect(err.Error()).To(ContainSubstring("usage"))
})
It("with invalid-resource and some flag", func() {
cmd := newDefaultCmd("invalid-resource", "--invalid-flag", "foo")
out, err := cmd.execute()
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("unknown command \"invalid-resource\" for \"create\""))
Expect(out).To(ContainSubstring("usage"))
Expect(err.Error()).To(ContainSubstring("Error: unknown command \"invalid-resource\" for \"create\""))
Expect(err.Error()).To(ContainSubstring("usage"))
})
It("with invalid-resource and additional argument", func() {
cmd := newDefaultCmd("invalid-resource", "foo")
out, err := cmd.execute()
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("unknown command \"invalid-resource\" for \"create\""))
Expect(out).To(ContainSubstring("usage"))
Expect(err.Error()).To(ContainSubstring("Error: unknown command \"invalid-resource\" for \"create\""))
Expect(err.Error()).To(ContainSubstring("usage"))
})
})
})
Expand Down Expand Up @@ -61,8 +62,13 @@ type mockVerbCmd struct {
}

func (c mockVerbCmd) execute() (string, error) {
buf := new(bytes.Buffer)
c.parentCmd.SetOut(buf)
outBuf := new(bytes.Buffer)
errBuf := new(bytes.Buffer)
c.parentCmd.SetOut(outBuf)
c.parentCmd.SetErr(errBuf)
err := c.parentCmd.Execute()
return buf.String(), err
if err != nil {
err = errors.New(errBuf.String())
}
return outBuf.String(), err
}
18 changes: 11 additions & 7 deletions pkg/ctl/create/fargate_test.go
Expand Up @@ -5,6 +5,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
)
Expand All @@ -15,17 +16,15 @@ var _ = Describe("create", func() {
cmd := newMockCreateFargateProfileCmd("fargateprofile")
out, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("--cluster must be set"))
Expect(out).To(ContainSubstring("Error: --cluster must be set"))
Expect(err.Error()).To(ContainSubstring("Error: --cluster must be set"))
Expect(out).To(ContainSubstring("Usage:"))
})

It("requires a Kubernetes namespace to be provided, and if missing, prints an error and the usage", func() {
cmd := newMockCreateFargateProfileCmd("fargateprofile", "--cluster", "foo")
out, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("invalid Fargate profile: empty selector namespace"))
Expect(out).To(ContainSubstring("Error: invalid Fargate profile: empty selector namespace"))
Expect(err.Error()).To(ContainSubstring("Error: invalid Fargate profile: empty selector namespace"))
Expect(out).To(ContainSubstring("Usage:"))
})

Expand Down Expand Up @@ -133,8 +132,13 @@ type mockCreateFargateProfileCmd struct {
}

func (c mockCreateFargateProfileCmd) execute() (string, error) {
buf := new(bytes.Buffer)
c.parentCmd.SetOut(buf)
outBuf := new(bytes.Buffer)
errBuf := new(bytes.Buffer)
c.parentCmd.SetOut(outBuf)
c.parentCmd.SetErr(errBuf)
err := c.parentCmd.Execute()
return buf.String(), err
if err != nil {
err = errors.New(errBuf.String())
}
return outBuf.String(), err
}
10 changes: 5 additions & 5 deletions pkg/ctl/create/iamserviceaccount_test.go
Expand Up @@ -39,23 +39,23 @@ var _ = Describe("create iamserviceaccount", func() {
cmd := newDefaultCmd(c.args...)
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(c.error.Error()))
Expect(err.Error()).To(ContainSubstring(c.error.Error()))
},
Entry("without cluster name", invalidParamsCase{
args: []string{"iamserviceaccount", "--name", "serviceAccountName"},
error: fmt.Errorf("--cluster must be set"),
error: fmt.Errorf("Error: --cluster must be set"),
}),
Entry("with iamserviceaccount name as argument and flag", invalidParamsCase{
args: []string{"iamserviceaccount", "--cluster", "clusterName", "--name", "serviceAccountName", "serviceAccountName"},
error: fmt.Errorf("--name=serviceAccountName and argument serviceAccountName cannot be used at the same time"),
error: fmt.Errorf("Error: --name=serviceAccountName and argument serviceAccountName cannot be used at the same time"),
}),
Entry("without required flag --attach-policy-arn", invalidParamsCase{
args: []string{"iamserviceaccount", "--cluster", "clusterName", "serviceAccountName"},
error: fmt.Errorf("--attach-policy-arn must be set"),
error: fmt.Errorf("Error: --attach-policy-arn must be set"),
}),
Entry("with invalid flags", invalidParamsCase{
args: []string{"iamserviceaccount", "--invalid", "dummy"},
error: fmt.Errorf("unknown flag: --invalid"),
error: fmt.Errorf("Error: unknown flag: --invalid"),
}),
)
})
30 changes: 18 additions & 12 deletions pkg/ctl/delete/delete_test.go
Expand Up @@ -2,6 +2,7 @@ package delete

import (
"bytes"
"errors"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -13,24 +14,24 @@ var _ = Describe("delete", func() {
Describe("invalid-resource", func() {
It("with no flag", func() {
cmd := newDefaultCmd("invalid-resource")
out, err := cmd.execute()
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("unknown command \"invalid-resource\" for \"delete\""))
Expect(out).To(ContainSubstring("usage"))
Expect(err.Error()).To(ContainSubstring("Error: unknown command \"invalid-resource\" for \"delete\""))
Expect(err.Error()).To(ContainSubstring("usage"))
})
It("with invalid-resource and some flag", func() {
cmd := newDefaultCmd("invalid-resource", "--invalid-flag", "foo")
out, err := cmd.execute()
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("unknown command \"invalid-resource\" for \"delete\""))
Expect(out).To(ContainSubstring("usage"))
Expect(err.Error()).To(ContainSubstring("Error: unknown command \"invalid-resource\" for \"delete\""))
Expect(err.Error()).To(ContainSubstring("usage"))
})
It("with invalid-resource and additional argument", func() {
cmd := newDefaultCmd("invalid-resource", "foo")
out, err := cmd.execute()
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("unknown command \"invalid-resource\" for \"delete\""))
Expect(out).To(ContainSubstring("usage"))
Expect(err.Error()).To(ContainSubstring("Error: unknown command \"invalid-resource\" for \"delete\""))
Expect(err.Error()).To(ContainSubstring("usage"))
})
})
})
Expand All @@ -57,8 +58,13 @@ type mockVerbCmd struct {
}

func (c mockVerbCmd) execute() (string, error) {
buf := new(bytes.Buffer)
c.parentCmd.SetOut(buf)
outBuf := new(bytes.Buffer)
errBuf := new(bytes.Buffer)
c.parentCmd.SetOut(outBuf)
c.parentCmd.SetErr(errBuf)
err := c.parentCmd.Execute()
return buf.String(), err
if err != nil {
err = errors.New(errBuf.String())
}
return outBuf.String(), err
}
21 changes: 12 additions & 9 deletions pkg/ctl/delete/fargate_test.go
Expand Up @@ -2,6 +2,7 @@ package delete

import (
"bytes"
"errors"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -16,17 +17,15 @@ var _ = Describe("delete", func() {
cmd := newMockDeleteFargateProfileCmd("fargateprofile")
out, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("--cluster must be set"))
Expect(out).To(ContainSubstring("Error: --cluster must be set"))
Expect(err.Error()).To(ContainSubstring("Error: --cluster must be set"))
Expect(out).To(ContainSubstring("Usage:"))
})

It("requires a profile name, and if missing, prints an error and the usage", func() {
cmd := newMockDeleteFargateProfileCmd("fargateprofile", "--cluster", "foo")
out, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("invalid Fargate profile: empty name"))
Expect(out).To(ContainSubstring("Error: invalid Fargate profile: empty name"))
Expect(err.Error()).To(ContainSubstring("Error: invalid Fargate profile: empty name"))
Expect(out).To(ContainSubstring("Usage:"))
})

Expand All @@ -50,8 +49,7 @@ var _ = Describe("delete", func() {
cmd := newMockDeleteFargateProfileCmd("fargateprofile", "-f", "../../../examples/01-simple-cluster.yaml")
out, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("invalid Fargate profile: empty name"))
Expect(out).To(ContainSubstring("Error: invalid Fargate profile: empty name"))
Expect(err.Error()).To(ContainSubstring("Error: invalid Fargate profile: empty name"))
Expect(out).To(ContainSubstring("Usage:"))
})

Expand Down Expand Up @@ -88,8 +86,13 @@ type mockDeleteFargateProfileCmd struct {
}

func (c mockDeleteFargateProfileCmd) execute() (string, error) {
buf := new(bytes.Buffer)
c.parentCmd.SetOut(buf)
outBuf := new(bytes.Buffer)
errBuf := new(bytes.Buffer)
c.parentCmd.SetOut(outBuf)
c.parentCmd.SetErr(errBuf)
err := c.parentCmd.Execute()
return buf.String(), err
if err != nil {
err = errors.New(errBuf.String())
}
return outBuf.String(), err
}
8 changes: 4 additions & 4 deletions pkg/ctl/delete/iamserviceaccount_test.go
Expand Up @@ -45,19 +45,19 @@ var _ = Describe("delete iamserviceaccount", func() {
cmd := newDefaultCmd(commandArgs...)
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(c.error.Error()))
Expect(err.Error()).To(ContainSubstring(c.error.Error()))
},
Entry("without cluster name", invalidParamsCase{
args: []string{"--name", "serviceAccountName"},
error: fmt.Errorf("--cluster must be set"),
error: fmt.Errorf("Error: --cluster must be set"),
}),
Entry("with iamserviceaccount name as argument and flag", invalidParamsCase{
args: []string{"--cluster", "clusterName", "--name", "serviceAccountName", "serviceAccountName"},
error: fmt.Errorf("--name=serviceAccountName and argument serviceAccountName cannot be used at the same time"),
error: fmt.Errorf("Error: --name=serviceAccountName and argument serviceAccountName cannot be used at the same time"),
}),
Entry("with invalid flags", invalidParamsCase{
args: []string{"iamserviceaccount", "--invalid", "dummy"},
error: fmt.Errorf("unknown flag: --invalid"),
error: fmt.Errorf("Error: unknown flag: --invalid"),
}),
)
})
6 changes: 3 additions & 3 deletions pkg/ctl/delete/nodegroup_test.go
Expand Up @@ -42,15 +42,15 @@ var _ = Describe("delete", func() {
cmd := newDefaultCmd(c.args...)
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(c.error.Error()))
Expect(err.Error()).To(ContainSubstring(c.error.Error()))
},
Entry("missing required flag --cluster", invalidParamsCase{
args: []string{"nodegroup"},
error: fmt.Errorf("--cluster must be set"),
error: fmt.Errorf("Error: --cluster must be set"),
}),
Entry("setting --name and argument at the same time", invalidParamsCase{
args: []string{"nodegroup", "ng", "--cluster", "dummy", "--name", "ng"},
error: fmt.Errorf("--name=ng and argument ng cannot be used at the same time"),
error: fmt.Errorf("Error: --name=ng and argument ng cannot be used at the same time"),
}),
)
})

0 comments on commit 285f53e

Please sign in to comment.