Skip to content

Commit

Permalink
Move e2e test to pipeline 0.44 and v1 resources
Browse files Browse the repository at this point in the history
This will move e2e tests to use pipeline 0.44 in CI
Move all te e2e tests to use v1 resources and get rid of
pipelineresources in pipeline, task and clustertasks tests

No need to run on minimal embedded status as that is ddefault on 0.44

Part of tektoncd#1804
  • Loading branch information
piyush-garg committed Mar 26, 2023
1 parent 914a9d0 commit 3c0386d
Show file tree
Hide file tree
Showing 26 changed files with 257 additions and 859 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/taskrun/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
cliopts "k8s.io/cli-runtime/pkg/genericclioptions"
)

const listTemplate = `{{- $trl := len .TaskRuns.Items -}}{{- if eq $trl 0 -}}
const ListTemplate = `{{- $trl := len .TaskRuns.Items -}}{{- if eq $trl 0 -}}
No TaskRuns found
{{ else -}}
{{- if not $.NoHeaders -}}
Expand Down Expand Up @@ -239,7 +239,7 @@ func printFormatted(s *cli.Stream, trs *v1.TaskRunList, c clockwork.Clock, allna
}

w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent)
t := template.Must(template.New("List TaskRuns").Funcs(funcMap).Parse(listTemplate))
t := template.Must(template.New("List TaskRuns").Funcs(funcMap).Parse(ListTemplate))

err := t.Execute(w, data)
if err != nil {
Expand Down
115 changes: 40 additions & 75 deletions test/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/jonboulle/clockwork"
pipelineCmd "github.com/tektoncd/cli/pkg/cmd/pipeline"
taskrunCmd "github.com/tektoncd/cli/pkg/cmd/taskrun"
"github.com/tektoncd/cli/pkg/formatted"
pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun/sort"
taskrunpkg "github.com/tektoncd/cli/pkg/taskrun/sort"
"github.com/tektoncd/cli/test/framework"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"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) *v1beta1.Task {
func GetTask(c *framework.Clients, name string) *v1.Task {

task, err := c.TaskClient.Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
Expand All @@ -55,7 +58,7 @@ func GetClusterTask(c *framework.Clients, name string) *v1beta1.ClusterTask {
return clustertask
}

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

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

Expand All @@ -74,7 +77,7 @@ func GetClusterTaskList(c *framework.Clients) *v1beta1.ClusterTaskList {
return clustertasklist
}

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

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

Expand All @@ -85,7 +88,7 @@ func GetTaskRun(c *framework.Clients, name string) *v1beta1.TaskRun {
return taskRun
}

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

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

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

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

Expand All @@ -128,7 +131,7 @@ func GetPipeline(c *framework.Clients, name string) *v1beta1.Pipeline {
return pipeline
}

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

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

Expand All @@ -139,7 +142,7 @@ func GetPipelineList(c *framework.Clients) *v1beta1.PipelineList {
return pipelineList
}

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

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

Expand All @@ -150,7 +153,7 @@ func GetPipelineRun(c *framework.Clients, name string) *v1beta1.PipelineRun {
return pipelineRun
}

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

if err == nil && sortByStartTime {
SortByStartTimePipelineRun(pipelineRunList.Items)
pipelinerunpkg.SortByStartTime(pipelineRunList.Items)
}

return pipelineRunList
}

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

if err == nil && sortByStartTime {
SortByStartTimeTaskRun(taskRunList.Items)
taskrunpkg.SortByStartTime(taskRunList.Items)
}

return taskRunList
}

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

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

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

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

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

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

if len(obj.Items) == 0 {

Expand All @@ -230,13 +233,13 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
}
w.Flush()
return tmplBytes.String()
case *v1beta1.TaskRunList:
case *v1.TaskRunList:
if len(obj.Items) == 0 {

return emptyMsg
}
// sort by start Time
SortByStartTimeTaskRun(obj.Items)
taskrunpkg.SortByStartTime(obj.Items)

for _, r := range obj.Items {
fmt.Fprintf(w, body,
Expand All @@ -245,7 +248,7 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
}
w.Flush()
return tmplBytes.String()
case *v1beta1.PipelineList:
case *v1.PipelineList:
if len(obj.Items) == 0 {
return emptyMsg
}
Expand All @@ -258,7 +261,7 @@ func ListResourceNamesForJSONPath(obj interface{}) string {
w.Flush()
return tmplBytes.String()

case *v1beta1.PipelineRunList:
case *v1.PipelineRunList:
if len(obj.Items) == 0 {
return emptyMsg
}
Expand Down Expand Up @@ -370,7 +373,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{}) *v1beta1.TaskList {
func GetTaskListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1.TaskList {
t.Helper()

tasklist := GetTaskList(c)
Expand Down Expand Up @@ -427,34 +430,24 @@ type TaskRunData struct {
Status string
}

func ListAllTaskRunsOutput(t *testing.T, cs *framework.Clients, allnamespaces bool, td map[int]interface{}) string {

const listTemplate = `{{- $trl := len .TaskRuns.Items }}{{ if eq $trl 0 -}}
No TaskRuns found
{{- else -}}
NAME STARTED DURATION STATUS{{- if $.AllNamespaces }} NAMESPACE{{- end }}
{{- range $_, $tr := .TaskRuns.Items }}
{{- if $tr }}
{{ $tr.Name }} {{ formatAge $tr.Status.StartTime $.Time }} {{ formatDuration $tr.Status.StartTime $tr.Status.CompletionTime }} {{ formatCondition $tr.Status.Conditions }}{{- if $.AllNamespaces }} {{ $tr.Namespace }}{{- end }}
{{- end }}
{{- end }}
{{- end }}
`
func ListAllTaskRunsOutput(t *testing.T, cs *framework.Clients, allnamespaces, noheaders bool, td map[int]interface{}) string {
clock := clockwork.NewFakeClockAt(time.Now())
taskrun := GetTaskRunListWithTestData(t, cs, td)
trslen := len(taskrun.Items)

if trslen != 0 {
SortByStartTimeTaskRun(taskrun.Items)
taskrunpkg.SortByStartTime(taskrun.Items)
}
var data = struct {
TaskRuns *v1beta1.TaskRunList
TaskRuns *v1.TaskRunList
Time clockwork.Clock
AllNamespaces bool
NoHeaders bool
}{
TaskRuns: taskrun,
Time: clock,
AllNamespaces: allnamespaces,
NoHeaders: noheaders,
}

funcMap := template.FuncMap{
Expand All @@ -465,7 +458,7 @@ NAME STARTED DURATION STATUS{{- if $.AllNamespaces }} NAMESPACE{{- end }}

var tmplBytes bytes.Buffer
w := tabwriter.NewWriter(&tmplBytes, 0, 5, 3, ' ', tabwriter.TabIndent)
tmp := template.Must(template.New("List TaskRuns").Funcs(funcMap).Parse(listTemplate))
tmp := template.Must(template.New("List TaskRuns").Funcs(funcMap).Parse(taskrunCmd.ListTemplate))

err := tmp.Execute(w, data)
if err != nil {
Expand All @@ -476,7 +469,7 @@ NAME STARTED DURATION STATUS{{- if $.AllNamespaces }} NAMESPACE{{- end }}
return tmplBytes.String()
}

func GetTaskRunListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1beta1.TaskRunList {
func GetTaskRunListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1.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 @@ -505,7 +498,7 @@ func GetTaskRunListWithTestData(t *testing.T, c *framework.Clients, td map[int]i
return taskRunlist
}

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

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

funcMap := template.FuncMap{
"accessMap": func(prs pipelineruns, name string) *v1beta1.PipelineRun {
"accessMap": func(prs pipelineruns, name string) *v1.PipelineRun {
if pr, ok := prs[name]; ok {
return &pr
}
Expand All @@ -573,7 +566,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{}) (*v1beta1.PipelineList, pipelineruns, error) {
func listPipelineDetailsWithTestData(t *testing.T, cs *framework.Clients, td map[int]interface{}) (*v1.PipelineList, pipelineruns, error) {
t.Helper()
ps := GetPipelineListWithTestData(t, cs, td)
runs := GetPipelineRunList(cs)
Expand All @@ -599,7 +592,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{}) *v1beta1.PipelineList {
func GetPipelineListWithTestData(t *testing.T, c *framework.Clients, td map[int]interface{}) *v1.PipelineList {
t.Helper()
ps := GetPipelineList(c)

Expand Down Expand Up @@ -645,21 +638,16 @@ func GetPipelineDescribeOutput(t *testing.T, cs *framework.Clients, pname string
t.Helper()
clock := clockwork.NewFakeClockAt(time.Now())

pipelineV1beta1 := GetPipelineWithTestData(t, cs, pname, td)
var pipelineV1 v1.Pipeline
err := pipelineV1beta1.ConvertTo(context.Background(), &pipelineV1)
if err != nil {
panic(err)
}
pipeline := GetPipelineWithTestData(t, cs, pname, td)
pipelineRuns := GetPipelineRunListWithNameAndTestData(t, cs, pname, td)

var data = struct {
Pipeline *v1.Pipeline
PipelineRuns *v1beta1.PipelineRunList
PipelineRuns *v1.PipelineRunList
PipelineName string
Time clockwork.Clock
}{
Pipeline: &pipelineV1,
Pipeline: pipeline,
PipelineRuns: pipelineRuns,
PipelineName: pname,
Time: clock,
Expand Down Expand Up @@ -694,37 +682,14 @@ func GetPipelineDescribeOutput(t *testing.T, cs *framework.Clients, pname string

}

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

for _, p := range td {
switch p := p.(type) {
case *PipelineDescribeData:
pipeline.Name = p.Name
if len(pipeline.Spec.Resources) == len(p.Resources) {
count := 0
for k, v := range p.Resources {
pipeline.Spec.Resources[count].Name = k
switch v {
case "git":
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypeGit
case "storage":
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypeStorage
case "image":
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypeImage
case "pullRequest":
pipeline.Spec.Resources[count].Type = v1beta1.PipelineResourceTypePullRequest
default:
t.Errorf("Provided PipelineResourcesData is not Valid Type : Need to Provide (%s, %s, %s)", v1beta1.PipelineResourceTypeGit, v1beta1.PipelineResourceTypeImage, v1beta1.PipelineResourceTypePullRequest)
}

count++
}
} else {
t.Errorf("length of Resources didn't match with testdata for pipeline %s", p.Name)
}

if len(pipeline.Spec.Tasks) == len(p.Task) {

for i, tref := range p.Task {
Expand Down Expand Up @@ -752,7 +717,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{}) *v1beta1.PipelineRunList {
func GetPipelineRunListWithNameAndTestData(t *testing.T, c *framework.Clients, pname string, td map[int]interface{}) *v1.PipelineRunList {
t.Helper()
opts := metav1.ListOptions{
LabelSelector: fmt.Sprintf("tekton.dev/pipeline=%s", pname),
Expand Down
Loading

0 comments on commit 3c0386d

Please sign in to comment.