Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
  • Loading branch information
shubham-cmyk committed Feb 19, 2024
1 parent 913db59 commit 48cd0a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
3 changes: 0 additions & 3 deletions pkg/runner/kubectl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ func Describe(collector *v1alpha1.Describe) (*v1alpha1.Command, error) {
if collector.Name != "" && collector.Selector != "" {
return nil, errors.New("name cannot be provided when a selector is specified")
}
if collector.Name == "" && collector.Selector == "" {
return nil, errors.New("a name or label selector must be specified")
}
cmd := v1alpha1.Command{
Cluster: collector.Cluster,
Entrypoint: "kubectl",
Expand Down
42 changes: 18 additions & 24 deletions pkg/runner/kubectl/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ func TestDescribe(t *testing.T) {
name: "with resource",
collector: &v1alpha1.Describe{
Resource: "foos",
ObjectLabelsSelector: v1alpha1.ObjectLabelsSelector{
Name: "foo",
},
},
want: &v1alpha1.Command{
Entrypoint: "kubectl",
Args: []string{"describe", "foos", "foo", "-n", "$NAMESPACE"},
Args: []string{"describe", "foos", "-n", "$NAMESPACE"},
},
wantErr: false,
},
Expand All @@ -69,12 +66,11 @@ func TestDescribe(t *testing.T) {
Resource: "foos",
ObjectLabelsSelector: v1alpha1.ObjectLabelsSelector{
Namespace: "bar",
Selector: "foo=bar",
},
},
want: &v1alpha1.Command{
Entrypoint: "kubectl",
Args: []string{"describe", "foos", "-l", "foo=bar", "-n", "bar"},
Args: []string{"describe", "foos", "-n", "bar"},
},
wantErr: false,
},
Expand All @@ -93,6 +89,18 @@ func TestDescribe(t *testing.T) {
},
wantErr: false,
},
{
name: "without name and selector",
collector: &v1alpha1.Describe{
Resource: "foos",
ObjectLabelsSelector: v1alpha1.ObjectLabelsSelector{},
},
want: &v1alpha1.Command{
Entrypoint: "kubectl",
Args: []string{"describe", "foos", "-n", "$NAMESPACE"},
},
wantErr: false,
},
{
name: "with selector",
collector: &v1alpha1.Describe{
Expand All @@ -118,14 +126,6 @@ func TestDescribe(t *testing.T) {
},
wantErr: true,
},
{
name: "withou name and selector",
collector: &v1alpha1.Describe{
Resource: "foos",
ObjectLabelsSelector: v1alpha1.ObjectLabelsSelector{},
},
wantErr: true,
},
{
name: "with namespace and selector",
collector: &v1alpha1.Describe{
Expand All @@ -144,30 +144,24 @@ func TestDescribe(t *testing.T) {
{
name: "with show-events marked as true",
collector: &v1alpha1.Describe{
Resource: "foos",
ObjectLabelsSelector: v1alpha1.ObjectLabelsSelector{
Name: "bar",
},
Resource: "foos",
ShowEvents: ptr.To[bool](true),
},
want: &v1alpha1.Command{
Entrypoint: "kubectl",
Args: []string{"describe", "foos", "bar", "-n", "$NAMESPACE", "--show-events=true"},
Args: []string{"describe", "foos", "-n", "$NAMESPACE", "--show-events=true"},
},
wantErr: false,
},
{
name: "with show-events marked as false",
collector: &v1alpha1.Describe{
Resource: "foos",
ObjectLabelsSelector: v1alpha1.ObjectLabelsSelector{
Name: "bar",
},
Resource: "foos",
ShowEvents: ptr.To[bool](false),
},
want: &v1alpha1.Command{
Entrypoint: "kubectl",
Args: []string{"describe", "foos", "bar", "-n", "$NAMESPACE", "--show-events=false"},
Args: []string{"describe", "foos", "-n", "$NAMESPACE", "--show-events=false"},
},
wantErr: false,
},
Expand Down

0 comments on commit 48cd0a4

Please sign in to comment.