Skip to content

Commit

Permalink
add namespace check to resource delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand authored and tekton-robot committed Oct 25, 2019
1 parent 64532a2 commit 44c108a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/cmd/pipelineresource/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/spf13/cobra"
"github.com/tektoncd/cli/pkg/cli"
validateinput "github.com/tektoncd/cli/pkg/helper/validate"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
cliopts "k8s.io/cli-runtime/pkg/genericclioptions"
)
Expand Down Expand Up @@ -56,6 +57,10 @@ tkn res rm foo -n bar
Err: cmd.OutOrStderr(),
}

if err := validateinput.NamespaceExists(p); err != nil {
return err
}

if err := checkOptions(opts, s, p, args[0]); err != nil {
return err
}
Expand Down
22 changes: 20 additions & 2 deletions pkg/cmd/pipelineresource/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinetest "github.com/tektoncd/pipeline/test"
tb "github.com/tektoncd/pipeline/test/builder"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestPipelineResourceDelete(t *testing.T) {
ns := []*corev1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ns",
},
},
}

seeds := make([]pipelinetest.Clients, 0)
for i := 0; i < 3; i++ {
pres := []*v1alpha1.PipelineResource{
Expand All @@ -35,7 +45,7 @@ func TestPipelineResourceDelete(t *testing.T) {
),
),
}
cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineResources: pres})
cs, _ := test.SeedTestData(t, pipelinetest.Data{PipelineResources: pres, Namespaces: ns})
seeds = append(seeds, cs)
}

Expand All @@ -47,6 +57,14 @@ func TestPipelineResourceDelete(t *testing.T) {
wantError bool
want string
}{
{
name: "Invalid namespace",
command: []string{"rm", "pre-1", "-n", "invalid"},
input: seeds[0],
inputStream: nil,
wantError: true,
want: "namespaces \"invalid\" not found",
},
{
name: "With force delete flag (shorthand)",
command: []string{"rm", "pre-1", "-n", "ns", "-f"},
Expand Down Expand Up @@ -91,7 +109,7 @@ func TestPipelineResourceDelete(t *testing.T) {

for _, tp := range testParams {
t.Run(tp.name, func(t *testing.T) {
p := &test.Params{Tekton: tp.input.Pipeline}
p := &test.Params{Tekton: tp.input.Pipeline, Kube: tp.input.Kube}
pipelineResource := Command(p)

if tp.inputStream != nil {
Expand Down

0 comments on commit 44c108a

Please sign in to comment.