Skip to content

Commit

Permalink
Fixes e2e test for ClusterTask
Browse files Browse the repository at this point in the history
For clustertask test, it use to fetch list of taskruns using label
`tekton.dev/task` instead of `tekton.dev/clusterTask`.

Fixes tektoncd#1319

Signed-off-by: Shivam Mukhade <[email protected]>
  • Loading branch information
SM43 authored and tekton-robot committed May 24, 2021
1 parent 951b5be commit bd86190
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
14 changes: 12 additions & 2 deletions test/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ func GetPipelineRunListWithName(c *framework.Clients, pname string, sortByStartT
return pipelineRunList
}

func GetTaskRunListWithName(c *framework.Clients, tname string, sortByStartTime bool) *v1alpha1.TaskRunList {
func GetTaskRunListByLabel(c *framework.Clients, tname string, sortByStartTime bool, label string) *v1alpha1.TaskRunList {
opts := metav1.ListOptions{
LabelSelector: fmt.Sprintf("tekton.dev/task=%s", tname),
LabelSelector: label,
}

time.Sleep(1 * time.Second)
Expand All @@ -183,6 +183,16 @@ func GetTaskRunListWithName(c *framework.Clients, tname string, sortByStartTime
return taskRunList
}

func GetTaskRunListWithTaskName(c *framework.Clients, tname string, sortByStartTime bool) *v1alpha1.TaskRunList {
label := fmt.Sprintf("tekton.dev/task=%s", tname)
return GetTaskRunListByLabel(c, tname, sortByStartTime, label)
}

func GetTaskRunListWithClusterTaskName(c *framework.Clients, ctname string, sortByStartTime bool) *v1alpha1.TaskRunList {
label := fmt.Sprintf("tekton.dev/clusterTask=%s", ctname)
return GetTaskRunListByLabel(c, ctname, sortByStartTime, label)
}

func GetPipelineRunList(c *framework.Clients) *v1alpha1.PipelineRunList {

pipelineRunList, err := c.PipelineRunClient.List(context.Background(), metav1.ListOptions{})
Expand Down
21 changes: 10 additions & 11 deletions test/e2e/clustertask/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const (
)

func TestClusterTaskInteractiveStartE2E(t *testing.T) {
t.Skip("TEMPORARY DISABLING THIS, SEE https://github.com/tektoncd/cli/issues/1319.")
t.Parallel()
c, namespace := framework.Setup(t)
knativetest.CleanupOnInterrupt(func() { framework.TearDown(t, c, namespace) }, t.Logf)
Expand Down Expand Up @@ -96,11 +95,11 @@ func TestClusterTaskInteractiveStartE2E(t *testing.T) {
"-i=source="+tePipelineGitResourceName,
"-p=FILEPATH=docs",
"-p=FILENAME=README.md",
"-w=name=shared-workspace,emptyDir=''",
"-w=name=shared-workspace,emptyDir=",
"--showlog")

vars := make(map[string]interface{})
taskRunGeneratedName := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name
vars["Taskrun"] = taskRunGeneratedName
expected := helper.ProcessString(`(TaskRun started: {{.Taskrun}}
Waiting for logs to be available...
Expand Down Expand Up @@ -148,7 +147,7 @@ Waiting for logs to be available...
c.Close()
return nil
}})
taskRunGeneratedName := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name
if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
Expand All @@ -161,7 +160,7 @@ Waiting for logs to be available...
"-w=name=shared-workspace,emptyDir=",
"--use-param-defaults",
"--showlog")
taskRunGeneratedName := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name
if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
Expand Down Expand Up @@ -195,7 +194,7 @@ Waiting for logs to be available...
c.Close()
return nil
}})
taskRunGeneratedName := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name
if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceed"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
Expand All @@ -214,15 +213,15 @@ Waiting for logs to be available...
"--showlog",
"--pod-template="+helper.GetResourcePath("/podtemplate/podtemplate.yaml"))

taskRunGeneratedName := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0].Name
if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceeded"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
})

t.Run("Start TaskRun using tkn ct start with --last option", func(t *testing.T) {
// Get last TaskRun for read-clustertask
lastTaskRun := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0]
lastTaskRun := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0]

// Start TaskRun using --last
tkn.MustSucceed(t, "ct", "start", clusterTaskName,
Expand All @@ -233,7 +232,7 @@ Waiting for logs to be available...
time.Sleep(1 * time.Second)

// Get name of most recent TaskRun and wait for it to succeed
taskRunUsingLast := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0]
taskRunUsingLast := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0]
if err := wait.ForTaskRunState(c, taskRunUsingLast.Name, wait.TaskRunSucceed(taskRunUsingLast.Name), "TaskRunSucceeded"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
Expand All @@ -248,7 +247,7 @@ Waiting for logs to be available...

t.Run("Start TaskRun using tkn ct start with --use-taskrun option", func(t *testing.T) {
// Get last TaskRun for read-clustertask
lastTaskRun := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0]
lastTaskRun := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0]

// Start TaskRun using --use-taskrun
tkn.MustSucceed(t, "ct", "start", clusterTaskName,
Expand All @@ -260,7 +259,7 @@ Waiting for logs to be available...
time.Sleep(1 * time.Second)

// Get name of most recent TaskRun and wait for it to succeed
taskRunUsingParticularTaskRun := builder.GetTaskRunListWithName(c, clusterTaskName, true).Items[0]
taskRunUsingParticularTaskRun := builder.GetTaskRunListWithClusterTaskName(c, clusterTaskName, true).Items[0]
if err := wait.ForTaskRunState(c, taskRunUsingParticularTaskRun.Name, wait.TaskRunSucceed(taskRunUsingParticularTaskRun.Name), "TaskRunSucceeded"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/task/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestTaskStartE2E(t *testing.T) {
"--showlog")

vars := make(map[string]interface{})
taskRunGeneratedName := builder.GetTaskRunListWithName(c, "read-task", true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithTaskName(c, "read-task", true).Items[0].Name
vars["Taskrun"] = taskRunGeneratedName
expected := helper.ProcessString(`(TaskRun started: {{.Taskrun}}
Waiting for logs to be available...
Expand Down Expand Up @@ -128,7 +128,7 @@ Waiting for logs to be available...
})

t.Run("Get list of TaskRuns from namespace "+namespace, func(t *testing.T) {
taskRuns := builder.GetTaskRunListWithName(c, "read-task", false)
taskRuns := builder.GetTaskRunListWithTaskName(c, "read-task", false)
taskRun1GeneratedName := taskRuns.Items[0].Name
taskRun2GeneratedName := taskRuns.Items[1].Name
taskRun3GeneratedName := taskRuns.Items[2].Name
Expand Down Expand Up @@ -231,7 +231,7 @@ Waiting for logs to be available...
"--workspace=name=read-allowed,volumeClaimTemplateFile="+helper.GetResourcePath("pvc.yaml"))

vars := make(map[string]interface{})
taskRunGeneratedName := builder.GetTaskRunListWithName(c, "task-with-workspace", true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithTaskName(c, "task-with-workspace", true).Items[0].Name
vars["Taskrun"] = taskRunGeneratedName
expected := helper.ProcessString(`(TaskRun started: {{.Taskrun}}
Waiting for logs to be available...
Expand All @@ -255,15 +255,15 @@ Waiting for logs to be available...
"--showlog",
"--pod-template="+helper.GetResourcePath("/podtemplate/podtemplate.yaml"))

taskRunGeneratedName := builder.GetTaskRunListWithName(c, "read-task", true).Items[0].Name
taskRunGeneratedName := builder.GetTaskRunListWithTaskName(c, "read-task", true).Items[0].Name
if err := wait.ForTaskRunState(c, taskRunGeneratedName, wait.TaskRunSucceed(taskRunGeneratedName), "TaskRunSucceeded"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
})

t.Run("Cancel finished TaskRun with tkn taskrun cancel", func(t *testing.T) {
// Get last TaskRun for read-task
taskRunLast := builder.GetTaskRunListWithName(c, "read-task", true).Items[0]
taskRunLast := builder.GetTaskRunListWithTaskName(c, "read-task", true).Items[0]

// Cancel TaskRun
res := tkn.Run("taskrun", "cancel", taskRunLast.Name)
Expand All @@ -281,7 +281,7 @@ Waiting for logs to be available...
tkn.MustSucceed(t, "task", "start", task, "-p", "seconds=30s")

// Get name of most recent TaskRun
taskRunName := builder.GetTaskRunListWithName(c, task, true).Items[0].Name
taskRunName := builder.GetTaskRunListWithTaskName(c, task, true).Items[0].Name

// Cancel TaskRun
res := tkn.MustSucceed(t, "taskrun", "cancel", taskRunName)
Expand All @@ -301,7 +301,7 @@ Waiting for logs to be available...

t.Run("Start TaskRun using tkn task start with --last option", func(t *testing.T) {
// Get last TaskRun for read-task
lastTaskRun := builder.GetTaskRunListWithName(c, "read-task", true).Items[0]
lastTaskRun := builder.GetTaskRunListWithTaskName(c, "read-task", true).Items[0]

// Start TaskRun using --last
tkn.MustSucceed(t, "task", "start", "read-task",
Expand All @@ -312,7 +312,7 @@ Waiting for logs to be available...
time.Sleep(1 * time.Second)

// Get name of most recent TaskRun and wait for it to succeed
taskRunUsingLast := builder.GetTaskRunListWithName(c, "read-task", true).Items[0]
taskRunUsingLast := builder.GetTaskRunListWithTaskName(c, "read-task", true).Items[0]
if err := wait.ForTaskRunState(c, taskRunUsingLast.Name, wait.TaskRunSucceed(taskRunUsingLast.Name), "TaskRunSucceeded"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
Expand Down

0 comments on commit bd86190

Please sign in to comment.