Skip to content

Commit

Permalink
Fix e2e test by converting to v1beta1 resources
Browse files Browse the repository at this point in the history
This will move all the structs and yaml resources
used in e2e for pipeline, pipelinerun, task, taskrun
and clustertask to v1beta1
  • Loading branch information
piyush-garg authored and tekton-robot committed Jul 27, 2022
1 parent 986905c commit ef347af
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 185 deletions.
81 changes: 40 additions & 41 deletions test/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import (
"github.com/jonboulle/clockwork"
"github.com/tektoncd/cli/pkg/formatted"
"github.com/tektoncd/cli/test/framework"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func GetTask(c *framework.Clients, name string) *v1alpha1.Task {
func GetTask(c *framework.Clients, name string) *v1beta1.Task {

task, err := c.TaskClient.Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
Expand All @@ -44,15 +45,15 @@ func GetTask(c *framework.Clients, name string) *v1alpha1.Task {
return task
}

func GetClusterTask(c *framework.Clients, name string) *v1alpha1.ClusterTask {
func GetClusterTask(c *framework.Clients, name string) *v1beta1.ClusterTask {
clustertask, err := c.ClusterTaskClient.Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
log.Fatalf("Couldn't get expected clustertask %s", err)
}
return clustertask
}

func GetTaskList(c *framework.Clients) *v1alpha1.TaskList {
func GetTaskList(c *framework.Clients) *v1beta1.TaskList {

tasklist, err := c.TaskClient.List(context.Background(), metav1.ListOptions{})

Expand All @@ -63,15 +64,15 @@ func GetTaskList(c *framework.Clients) *v1alpha1.TaskList {
return tasklist
}

func GetClusterTaskList(c *framework.Clients) *v1alpha1.ClusterTaskList {
func GetClusterTaskList(c *framework.Clients) *v1beta1.ClusterTaskList {
clustertasklist, err := c.ClusterTaskClient.List(context.Background(), metav1.ListOptions{})
if err != nil {
log.Fatalf("Couldn't get expected clustertasklist %s", err)
}
return clustertasklist
}

func GetTaskRun(c *framework.Clients, name string) *v1alpha1.TaskRun {
func GetTaskRun(c *framework.Clients, name string) *v1beta1.TaskRun {

taskRun, err := c.TaskRunClient.Get(context.Background(), name, metav1.GetOptions{})

Expand All @@ -82,7 +83,7 @@ func GetTaskRun(c *framework.Clients, name string) *v1alpha1.TaskRun {
return taskRun
}

func GetTaskRunList(c *framework.Clients) *v1alpha1.TaskRunList {
func GetTaskRunList(c *framework.Clients) *v1beta1.TaskRunList {
taskRunlist, err := c.TaskRunClient.List(context.Background(), metav1.ListOptions{})

if err != nil {
Expand Down Expand Up @@ -114,7 +115,7 @@ func GetPipelineResourceList(c *framework.Clients) *v1alpha1.PipelineResourceLis
return pipelineResourceList
}

func GetPipeline(c *framework.Clients, name string) *v1alpha1.Pipeline {
func GetPipeline(c *framework.Clients, name string) *v1beta1.Pipeline {

pipeline, err := c.PipelineClient.Get(context.Background(), name, metav1.GetOptions{})

Expand All @@ -125,7 +126,7 @@ func GetPipeline(c *framework.Clients, name string) *v1alpha1.Pipeline {
return pipeline
}

func GetPipelineList(c *framework.Clients) *v1alpha1.PipelineList {
func GetPipelineList(c *framework.Clients) *v1beta1.PipelineList {

pipelineList, err := c.PipelineClient.List(context.Background(), metav1.ListOptions{})

Expand All @@ -136,7 +137,7 @@ func GetPipelineList(c *framework.Clients) *v1alpha1.PipelineList {
return pipelineList
}

func GetPipelineRun(c *framework.Clients, name string) *v1alpha1.PipelineRun {
func GetPipelineRun(c *framework.Clients, name string) *v1beta1.PipelineRun {

pipelineRun, err := c.PipelineRunClient.Get(context.Background(), name, metav1.GetOptions{})

Expand All @@ -147,7 +148,7 @@ func GetPipelineRun(c *framework.Clients, name string) *v1alpha1.PipelineRun {
return pipelineRun
}

func GetPipelineRunListWithName(c *framework.Clients, pname string, sortByStartTime bool) *v1alpha1.PipelineRunList {
func GetPipelineRunListWithName(c *framework.Clients, pname string, sortByStartTime bool) *v1beta1.PipelineRunList {
opts := metav1.ListOptions{
LabelSelector: fmt.Sprintf("tekton.dev/pipeline=%s", pname),
}
Expand All @@ -164,7 +165,7 @@ func GetPipelineRunListWithName(c *framework.Clients, pname string, sortByStartT
return pipelineRunList
}

func GetTaskRunListByLabel(c *framework.Clients, tname string, sortByStartTime bool, label string) *v1alpha1.TaskRunList {
func GetTaskRunListByLabel(c *framework.Clients, tname string, sortByStartTime bool, label string) *v1beta1.TaskRunList {
opts := metav1.ListOptions{
LabelSelector: label,
}
Expand All @@ -183,17 +184,17 @@ func GetTaskRunListByLabel(c *framework.Clients, tname string, sortByStartTime b
return taskRunList
}

func GetTaskRunListWithTaskName(c *framework.Clients, tname string, sortByStartTime bool) *v1alpha1.TaskRunList {
func GetTaskRunListWithTaskName(c *framework.Clients, tname string, sortByStartTime bool) *v1beta1.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 {
func GetTaskRunListWithClusterTaskName(c *framework.Clients, ctname string, sortByStartTime bool) *v1beta1.TaskRunList {
label := fmt.Sprintf("tekton.dev/clusterTask=%s", ctname)
return GetTaskRunListByLabel(c, ctname, sortByStartTime, label)
}

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

pipelineRunList, err := c.PipelineRunClient.List(context.Background(), metav1.ListOptions{})

Expand All @@ -213,7 +214,7 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
w := tabwriter.NewWriter(&tmplBytes, 0, 5, 3, ' ', tabwriter.TabIndent)

switch obj := obj.(type) {
case *v1alpha1.TaskList:
case *v1beta1.TaskList:

if len(obj.Items) == 0 {

Expand All @@ -227,7 +228,7 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
}
w.Flush()
return tmplBytes.String()
case *v1alpha1.TaskRunList:
case *v1beta1.TaskRunList:
if len(obj.Items) == 0 {

return emptyMsg
Expand All @@ -242,7 +243,7 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
}
w.Flush()
return tmplBytes.String()
case *v1alpha1.PipelineList:
case *v1beta1.PipelineList:
if len(obj.Items) == 0 {
return emptyMsg
}
Expand All @@ -255,7 +256,7 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
w.Flush()
return tmplBytes.String()

case *v1alpha1.PipelineRunList:
case *v1beta1.PipelineRunList:
if len(obj.Items) == 0 {
return emptyMsg
}
Expand All @@ -279,7 +280,7 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
}
w.Flush()
return tmplBytes.String()
case *v1alpha1.ClusterTaskList:
case *v1beta1.ClusterTaskList:
if len(obj.Items) == 0 {
return emptyMsg
}
Expand Down Expand Up @@ -367,7 +368,7 @@ func ListAllClusterTasksOutput(t *testing.T, cs *framework.Clients, td map[int]i
return tmplBytes.String()
}

func GetTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1alpha1.TaskList {
func GetTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1beta1.TaskList {
t.Helper()

tasklist := GetTaskList(c)
Expand All @@ -393,7 +394,7 @@ func GetTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]inte
return tasklist
}

func GetClusterTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1alpha1.ClusterTaskList {
func GetClusterTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1beta1.ClusterTaskList {
t.Helper()

clustertasklist := GetClusterTaskList(c)
Expand Down Expand Up @@ -445,7 +446,7 @@ NAME STARTED DURATION STATUS{{- if $.AllNamespaces }} NAMESPACE{{- end }}
SortByStartTimeTaskRun(taskrun.Items)
}
var data = struct {
TaskRuns *v1alpha1.TaskRunList
TaskRuns *v1beta1.TaskRunList
Time clockwork.Clock
AllNamespaces bool
}{
Expand Down Expand Up @@ -473,7 +474,7 @@ NAME STARTED DURATION STATUS{{- if $.AllNamespaces }} NAMESPACE{{- end }}
return tmplBytes.String()
}

func GetTaskRunListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1alpha1.TaskRunList {
func GetTaskRunListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1beta1.TaskRunList {
taskRunlist := GetTaskRunList(c)
if len(taskRunlist.Items) != len(td) {
t.Errorf("Length of taskrun list and Testdata provided not matching")
Expand Down Expand Up @@ -502,7 +503,7 @@ func GetTaskRunListWithTestData(t *testing.T, c *framework.Clients, td map[int]i
return taskRunlist
}

type pipelineruns map[string]v1alpha1.PipelineRun
type pipelineruns map[string]v1beta1.PipelineRun

type PipelinesListData struct {
Name string
Expand Down Expand Up @@ -533,7 +534,7 @@ func ListAllPipelinesOutput(t *testing.T, cs *framework.Clients, td map[int]inte
t.Error("Failed to list pipelines")
}
var data = struct {
Pipelines *v1alpha1.PipelineList
Pipelines *v1beta1.PipelineList
PipelineRuns pipelineruns
Params clockwork.Clock
}{
Expand All @@ -543,7 +544,7 @@ func ListAllPipelinesOutput(t *testing.T, cs *framework.Clients, td map[int]inte
}

funcMap := template.FuncMap{
"accessMap": func(prs pipelineruns, name string) *v1alpha1.PipelineRun {
"accessMap": func(prs pipelineruns, name string) *v1beta1.PipelineRun {
if pr, ok := prs[name]; ok {
return &pr
}
Expand All @@ -570,7 +571,7 @@ func ListAllPipelinesOutput(t *testing.T, cs *framework.Clients, td map[int]inte
return tmplBytes.String()
}

func listPipelineDetailsWithTestData(t *testing.T, cs *framework.Clients, td map[int]interface{}) (*v1alpha1.PipelineList, pipelineruns, error) {
func listPipelineDetailsWithTestData(t *testing.T, cs *framework.Clients, td map[int]interface{}) (*v1beta1.PipelineList, pipelineruns, error) {
t.Helper()
ps := GetPipelineListWithTestData(t, cs, td)
runs := GetPipelineRunList(cs)
Expand All @@ -596,7 +597,7 @@ func listPipelineDetailsWithTestData(t *testing.T, cs *framework.Clients, td map
return ps, latestRuns, nil
}

func GetPipelineListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1alpha1.PipelineList {
func GetPipelineListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1beta1.PipelineList {
t.Helper()
ps := GetPipelineList(c)

Expand Down Expand Up @@ -718,8 +719,8 @@ func GetPipelineDescribeOutput(t *testing.T, cs *framework.Clients, pname string
pipelineRuns := GetPipelineRunListWithNameAndTestData(t, cs, pname, td)

var data = struct {
Pipeline *v1alpha1.Pipeline
PipelineRuns *v1alpha1.PipelineRunList
Pipeline *v1beta1.Pipeline
PipelineRuns *v1beta1.PipelineRunList
PipelineName string
Params clockwork.Clock
}{
Expand Down Expand Up @@ -756,7 +757,7 @@ func GetPipelineDescribeOutput(t *testing.T, cs *framework.Clients, pname string

}

func GetPipelineWithTestData(t *testing.T, c *framework.Clients, name string, td map[int]interface{}) *v1alpha1.Pipeline {
func GetPipelineWithTestData(t *testing.T, c *framework.Clients, name string, td map[int]interface{}) *v1beta1.Pipeline {
t.Helper()
pipeline := GetPipeline(c, name)

Expand All @@ -770,19 +771,17 @@ func GetPipelineWithTestData(t *testing.T, c *framework.Clients, name string, td
pipeline.Spec.Resources[count].Name = k
switch v {
case "git":
pipeline.Spec.Resources[count].Type = v1alpha1.PipelineResourceTypeGit
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypeGit
case "storage":
pipeline.Spec.Resources[count].Type = v1alpha1.PipelineResourceTypeStorage
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypeStorage
case "image":
pipeline.Spec.Resources[count].Type = v1alpha1.PipelineResourceTypeImage
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypeImage
case "cluster":
pipeline.Spec.Resources[count].Type = v1alpha1.PipelineResourceTypeCluster
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypeCluster
case "pullRequest":
pipeline.Spec.Resources[count].Type = v1alpha1.PipelineResourceTypePullRequest
case "gcs":
pipeline.Spec.Resources[count].Type = v1alpha1.PipelineResourceTypeGCS
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypePullRequest
default:
t.Errorf("Provided PipelineResourcesData is not Valid Type : Need to Provide (%s, %s, %s, %s)", v1alpha1.PipelineResourceTypeGit, v1alpha1.PipelineResourceTypeImage, v1alpha1.PipelineResourceTypePullRequest, v1alpha1.PipelineResourceTypeCluster)
t.Errorf("Provided PipelineResourcesData is not Valid Type : Need to Provide (%s, %s, %s, %s)", v1beta1.PipelineResourceTypeGit, v1beta1.PipelineResourceTypeImage, v1beta1.PipelineResourceTypePullRequest, v1beta1.PipelineResourceTypeCluster)
}

count++
Expand Down Expand Up @@ -818,7 +817,7 @@ func GetPipelineWithTestData(t *testing.T, c *framework.Clients, name string, td
return pipeline
}

func GetPipelineRunListWithNameAndTestData(t *testing.T, c *framework.Clients, pname string, td map[int]interface{}) *v1alpha1.PipelineRunList {
func GetPipelineRunListWithNameAndTestData(t *testing.T, c *framework.Clients, pname string, td map[int]interface{}) *v1beta1.PipelineRunList {
t.Helper()
opts := metav1.ListOptions{
LabelSelector: fmt.Sprintf("tekton.dev/pipeline=%s", pname),
Expand Down
10 changes: 5 additions & 5 deletions test/builder/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ package builder
import (
"sort"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
)

func SortByStartTimeTaskRun(trs []v1alpha1.TaskRun) {
func SortByStartTimeTaskRun(trs []v1beta1.TaskRun) {
sort.Sort(byStartTimeTR(trs))
}

func SortByStartTimePipelineRun(prs []v1alpha1.PipelineRun) {
func SortByStartTimePipelineRun(prs []v1beta1.PipelineRun) {
sort.Sort(byStartTimePR(prs))
}

type byStartTimeTR []v1alpha1.TaskRun
type byStartTimeTR []v1beta1.TaskRun

func (trs byStartTimeTR) Len() int { return len(trs) }
func (trs byStartTimeTR) Swap(i, j int) { trs[i], trs[j] = trs[j], trs[i] }
Expand All @@ -42,7 +42,7 @@ func (trs byStartTimeTR) Less(i, j int) bool {
return trs[j].Status.StartTime.Before(trs[i].Status.StartTime)
}

type byStartTimePR []v1alpha1.PipelineRun
type byStartTimePR []v1beta1.PipelineRun

func (prs byStartTimePR) Len() int { return len(prs) }
func (prs byStartTimePR) Swap(i, j int) { prs[i], prs[j] = prs[j], prs[i] }
Expand Down
15 changes: 8 additions & 7 deletions test/builder/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import (
"sort"
"strings"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
corev1 "k8s.io/api/core/v1"
)

func Details(pre v1alpha1.PipelineResource) string {
var key = "url"
if pre.Spec.Type == v1alpha1.PipelineResourceTypeStorage {
if pre.Spec.Type == v1beta1.PipelineResourceTypeStorage {
key = "location"
}
if pre.Spec.Type == v1alpha1.PipelineResourceTypeCloudEvent {
if pre.Spec.Type == v1beta1.PipelineResourceTypeCloudEvent {
key = "targeturi"
}

Expand All @@ -41,7 +42,7 @@ func Details(pre v1alpha1.PipelineResource) string {
return "---"
}

func TaskRunHasFailed(tr *v1alpha1.TaskRun) string {
func TaskRunHasFailed(tr *v1beta1.TaskRun) string {
if len(tr.Status.Conditions) == 0 {
return ""
}
Expand All @@ -53,7 +54,7 @@ func TaskRunHasFailed(tr *v1alpha1.TaskRun) string {
}

// this will sort the Resource by Type and then by Name
func SortResourcesByTypeAndName(pres []v1alpha1.PipelineDeclaredResource) []v1alpha1.PipelineDeclaredResource {
func SortResourcesByTypeAndName(pres []v1beta1.PipelineDeclaredResource) []v1beta1.PipelineDeclaredResource {
sort.Slice(pres, func(i, j int) bool {
if pres[j].Type < pres[i].Type {
return false
Expand All @@ -71,7 +72,7 @@ func SortResourcesByTypeAndName(pres []v1alpha1.PipelineDeclaredResource) []v1al

// Pipeline Run Describe command

func PipelineRunHasFailed(pr *v1alpha1.PipelineRun) string {
func PipelineRunHasFailed(pr *v1beta1.PipelineRun) string {
if len(pr.Status.Conditions) == 0 {
return ""
}
Expand All @@ -95,7 +96,7 @@ type TaskrunList []tkr

type tkr struct {
TaskrunName string
*v1alpha1.PipelineRunTaskRunStatus
*v1beta1.PipelineRunTaskRunStatus
}

func (s TaskrunList) Len() int { return len(s) }
Expand Down
Loading

0 comments on commit ef347af

Please sign in to comment.