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

Add Namespace Check to Taskrun Delete Command #373

Merged
merged 1 commit into from
Oct 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/cmd/taskrun/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"
validate "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 tr rm foo -n bar
Err: cmd.OutOrStderr(),
}

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

if err := checkOptions(opts, s, p, args[0]); err != nil {
return err
}
Expand Down
21 changes: 19 additions & 2 deletions pkg/cmd/taskrun/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ import (
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"
"knative.dev/pkg/apis"
)

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

seeds := make([]pipelinetest.Clients, 0)
for i := 0; i < 3; i++ {
trs := []*v1alpha1.TaskRun{
Expand All @@ -43,7 +52,7 @@ func TestTaskRunDelete(t *testing.T) {
),
),
}
cs, _ := test.SeedTestData(t, pipelinetest.Data{TaskRuns: trs})
cs, _ := test.SeedTestData(t, pipelinetest.Data{TaskRuns: trs, Namespaces: ns})
seeds = append(seeds, cs)
}

Expand All @@ -55,6 +64,14 @@ func TestTaskRunDelete(t *testing.T) {
wantError bool
want string
}{
{
name: "Invalid namespace",
command: []string{"rm", "tr0-1", "-n", "invalid"},
input: seeds[0],
inputStream: nil,
wantError: true,
want: "namespaces \"invalid\" not found",
},
{
name: "With force delete flag (shorthand)",
command: []string{"rm", "tr0-1", "-n", "ns", "-f"},
Expand Down Expand Up @@ -99,7 +116,7 @@ func TestTaskRunDelete(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}
taskrun := Command(p)

if tp.inputStream != nil {
Expand Down