diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index 78ff6a45c..dccbe251f 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -143,7 +143,7 @@ ci_run && { echo "Go Build successfull" export TEST_CLIENT_BINARY=$PWD/tkn fi - go_test_e2e ./test/e2e || failed=1 + go_test_e2e ./test/e2e/... || failed=1 (( failed )) && fail_test } diff --git a/test/e2e/pipeline_e2e_test.go b/test/e2e/pipeline/pipeline_test.go similarity index 88% rename from test/e2e/pipeline_e2e_test.go rename to test/e2e/pipeline/pipeline_test.go index 463694cc3..1a07d8e5a 100644 --- a/test/e2e/pipeline_e2e_test.go +++ b/test/e2e/pipeline/pipeline_test.go @@ -1,3 +1,4 @@ +// +build e2e // Copyright © 2020 The Tekton Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package e2e +package pipeline import ( "encoding/json" @@ -24,6 +25,7 @@ import ( "github.com/AlecAivazis/survey/v2/terminal" "github.com/Netflix/go-expect" + "github.com/tektoncd/cli/test/e2e" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" tb "github.com/tektoncd/pipeline/test/builder" "gotest.tools/v3/assert" @@ -42,11 +44,11 @@ const ( func TestPipelinesE2E(t *testing.T) { t.Parallel() - c, namespace := Setup(t) - knativetest.CleanupOnInterrupt(func() { TearDown(t, c, namespace) }, t.Logf) - defer TearDown(t, c, namespace) + c, namespace := e2e.Setup(t) + knativetest.CleanupOnInterrupt(func() { e2e.TearDown(t, c, namespace) }, t.Logf) + defer e2e.TearDown(t, c, namespace) - tkn, err := NewTknRunner(namespace) + tkn, err := e2e.NewTknRunner(namespace) if err != nil { t.Fatalf("Error creating tknRunner %+v", err) } @@ -75,11 +77,11 @@ func TestPipelinesE2E(t *testing.T) { t.Run("Get list of Tasks from namespace "+namespace, func(t *testing.T) { res := tkn.Run("task", "list") - expected := ListAllTasksOutput(t, c, map[int]interface{}{ - 0: &TaskData{ + expected := e2e.ListAllTasksOutput(t, c, map[int]interface{}{ + 0: &e2e.TaskData{ Name: TaskName2, }, - 1: &TaskData{ + 1: &e2e.TaskData{ Name: TaskName1, }, }) @@ -94,8 +96,8 @@ func TestPipelinesE2E(t *testing.T) { t.Run("Get list of Pipelines from namespace "+namespace, func(t *testing.T) { res := tkn.Run("pipelines", "list") - expected := ListAllPipelinesOutput(t, c, map[int]interface{}{ - 0: &PipelinesListData{ + expected := e2e.ListAllPipelinesOutput(t, c, map[int]interface{}{ + 0: &e2e.PipelinesListData{ Name: tePipelineName, Status: "---", }, @@ -108,7 +110,7 @@ func TestPipelinesE2E(t *testing.T) { }) }) - // Bug to fix + t.Run("Get list of pipelines from other namespace [default] should throw Error", func(t *testing.T) { res := tkn.RunNoNamespace("pipelines", "list", "-n", "default") @@ -123,10 +125,10 @@ func TestPipelinesE2E(t *testing.T) { res := tkn.Run("pipelines", "list", `-o=jsonpath={range.items[*]}{.metadata.name}{"\n"}{end}`) - expected := ListResourceNamesForJSONPath( - GetPipelineListWithTestData(t, c, + expected := e2e.ListResourceNamesForJSONPath( + e2e.GetPipelineListWithTestData(t, c, map[int]interface{}{ - 0: &PipelinesListData{ + 0: &e2e.PipelinesListData{ Name: tePipelineName, Status: "---", }, @@ -156,20 +158,20 @@ func TestPipelinesE2E(t *testing.T) { t.Run("Validate Pipeline describe command in namespace "+namespace, func(t *testing.T) { res := tkn.Run("pipeline", "describe", tePipelineName) - expected := GetPipelineDescribeOutput(t, c, tePipelineName, + expected := e2e.GetPipelineDescribeOutput(t, c, tePipelineName, map[int]interface{}{ - 0: &PipelineDescribeData{ + 0: &e2e.PipelineDescribeData{ Name: tePipelineName, Resources: map[string]string{ "source-repo": "git", }, Task: map[int]interface{}{ - 0: &TaskRefData{ + 0: &e2e.TaskRefData{ TaskName: "first-create-file", TaskRef: TaskName1, RunAfter: nil, }, - 1: &TaskRefData{ + 1: &e2e.TaskRefData{ TaskName: "then-check", TaskRef: TaskName2, RunAfter: nil, @@ -198,9 +200,9 @@ func TestPipelinesE2E(t *testing.T) { time.Sleep(1 * time.Second) - pipelineGeneratedName = GetPipelineRunListWithName(c, tePipelineName).Items[0].Name + pipelineGeneratedName = e2e.GetPipelineRunListWithName(c, tePipelineName).Items[0].Name vars["Element"] = pipelineGeneratedName - expected := ProcessString(`(Pipelinerun started: {{.Element}} + expected := e2e.ProcessString(`(Pipelinerun started: {{.Element}} Waiting for logs to be available... .*)`, vars) @@ -217,12 +219,12 @@ Waiting for logs to be available... t.Run("Get list of Taskruns from namespace "+namespace, func(t *testing.T) { res := tkn.Run("taskrun", "list") - expected := ListAllTaskRunsOutput(t, c, false, map[int]interface{}{ - 0: &TaskRunData{ + expected := e2e.ListAllTaskRunsOutput(t, c, false, map[int]interface{}{ + 0: &e2e.TaskRunData{ Name: "output-pipeline-run-", Status: "Succeeded", }, - 1: &TaskRunData{ + 1: &e2e.TaskRunData{ Name: "output-pipeline-run-", Status: "Succeeded", }, @@ -239,20 +241,20 @@ Waiting for logs to be available... t.Run("Validate Pipeline describe command in namespace "+namespace+" after PipelineRun completed successfully", func(t *testing.T) { res := tkn.Run("pipeline", "describe", tePipelineName) - expected := GetPipelineDescribeOutput(t, c, tePipelineName, + expected := e2e.GetPipelineDescribeOutput(t, c, tePipelineName, map[int]interface{}{ - 0: &PipelineDescribeData{ + 0: &e2e.PipelineDescribeData{ Name: tePipelineName, Resources: map[string]string{ "source-repo": "git", }, Task: map[int]interface{}{ - 0: &TaskRefData{ + 0: &e2e.TaskRefData{ TaskName: "first-create-file", TaskRef: TaskName1, RunAfter: nil, }, - 1: &TaskRefData{ + 1: &e2e.TaskRefData{ TaskName: "then-check", TaskRef: TaskName2, RunAfter: nil, @@ -273,7 +275,7 @@ Waiting for logs to be available... }) t.Run("Validate interactive pipeline logs, with follow mode (-f) ", func(t *testing.T) { - RunInteractiveTests(t, namespace, tkn.Path(), &Prompt{ + e2e.RunInteractiveTests(t, namespace, tkn.Path(), &e2e.Prompt{ CmdArgs: []string{"pipeline", "logs", "-f", "-n", namespace}, Procedure: func(c *expect.Console) error { if _, err := c.ExpectString("Select pipeline:"); err != nil { @@ -300,11 +302,11 @@ Waiting for logs to be available... func TestPipelinesNegativeE2E(t *testing.T) { t.Parallel() - c, namespace := Setup(t) - knativetest.CleanupOnInterrupt(func() { TearDown(t, c, namespace) }, t.Logf) - defer TearDown(t, c, namespace) + c, namespace := e2e.Setup(t) + knativetest.CleanupOnInterrupt(func() { e2e.TearDown(t, c, namespace) }, t.Logf) + defer e2e.TearDown(t, c, namespace) - tkn, err := NewTknRunner(namespace) + tkn, err := e2e.NewTknRunner(namespace) if err != nil { t.Fatalf("Error creating tknRunner %+v", err) } @@ -334,8 +336,8 @@ func TestPipelinesNegativeE2E(t *testing.T) { t.Run("Get list of Pipelines from namespace "+namespace, func(t *testing.T) { res := tkn.Run("pipelines", "list") - expected := ListAllPipelinesOutput(t, c, map[int]interface{}{ - 0: &PipelinesListData{ + expected := e2e.ListAllPipelinesOutput(t, c, map[int]interface{}{ + 0: &e2e.PipelinesListData{ Name: tePipelineName, Status: "---", }, @@ -363,10 +365,10 @@ func TestPipelinesNegativeE2E(t *testing.T) { res := tkn.Run("pipelines", "list", `-o=jsonpath={range.items[*]}{.metadata.name}{"\n"}{end}`) - expected := ListResourceNamesForJSONPath( - GetPipelineListWithTestData(t, c, + expected := e2e.ListResourceNamesForJSONPath( + e2e.GetPipelineListWithTestData(t, c, map[int]interface{}{ - 0: &PipelinesListData{ + 0: &e2e.PipelinesListData{ Name: tePipelineName, Status: "---", }, @@ -395,20 +397,20 @@ func TestPipelinesNegativeE2E(t *testing.T) { t.Run("Validate Pipeline describe command in namespace "+namespace, func(t *testing.T) { res := tkn.Run("pipeline", "describe", tePipelineName) - expected := GetPipelineDescribeOutput(t, c, tePipelineName, + expected := e2e.GetPipelineDescribeOutput(t, c, tePipelineName, map[int]interface{}{ - 0: &PipelineDescribeData{ + 0: &e2e.PipelineDescribeData{ Name: tePipelineName, Resources: map[string]string{ "source-repo": "git", }, Task: map[int]interface{}{ - 0: &TaskRefData{ + 0: &e2e.TaskRefData{ TaskName: "first-create-file", TaskRef: TaskName1, RunAfter: nil, }, - 1: &TaskRefData{ + 1: &e2e.TaskRefData{ TaskName: "then-check", TaskRef: TaskName2, RunAfter: nil, @@ -434,9 +436,9 @@ func TestPipelinesNegativeE2E(t *testing.T) { "--showlog", "true") - pipelineGeneratedName = GetPipelineRunListWithName(c, tePipelineName).Items[0].Name + pipelineGeneratedName = e2e.GetPipelineRunListWithName(c, tePipelineName).Items[0].Name vars["Element"] = pipelineGeneratedName - expected := ProcessString(`(Pipelinerun started: {{.Element}} + expected := e2e.ProcessString(`(Pipelinerun started: {{.Element}} Waiting for logs to be available... .*)`, vars) @@ -451,20 +453,20 @@ Waiting for logs to be available... t.Run("Validate Pipeline describe command in namespace "+namespace+" after PipelineRun completed successfully", func(t *testing.T) { res := tkn.Run("pipeline", "describe", tePipelineName) - expected := GetPipelineDescribeOutput(t, c, tePipelineName, + expected := e2e.GetPipelineDescribeOutput(t, c, tePipelineName, map[int]interface{}{ - 0: &PipelineDescribeData{ + 0: &e2e.PipelineDescribeData{ Name: tePipelineName, Resources: map[string]string{ "source-repo": "git", }, Task: map[int]interface{}{ - 0: &TaskRefData{ + 0: &e2e.TaskRefData{ TaskName: "first-create-file", TaskRef: TaskName1, RunAfter: nil, }, - 1: &TaskRefData{ + 1: &e2e.TaskRefData{ TaskName: "then-check", TaskRef: TaskName2, RunAfter: nil, @@ -488,11 +490,11 @@ Waiting for logs to be available... func TestDeletePipelinesE2E(t *testing.T) { t.Parallel() - c, namespace := Setup(t) - knativetest.CleanupOnInterrupt(func() { TearDown(t, c, namespace) }, t.Logf) - defer TearDown(t, c, namespace) + c, namespace := e2e.Setup(t) + knativetest.CleanupOnInterrupt(func() { e2e.TearDown(t, c, namespace) }, t.Logf) + defer e2e.TearDown(t, c, namespace) - tkn, err := NewTknRunner(namespace) + tkn, err := e2e.NewTknRunner(namespace) if err != nil { t.Fatalf("Error creating tknRunner %+v", err) } diff --git a/test/e2e/task_start_e2e_test.go b/test/e2e/task/task_start_test.go similarity index 70% rename from test/e2e/task_start_e2e_test.go rename to test/e2e/task/task_start_test.go index 000fbe8c9..eee103dd2 100644 --- a/test/e2e/task_start_e2e_test.go +++ b/test/e2e/task/task_start_test.go @@ -1,3 +1,4 @@ +// +build e2e // Copyright © 2020 The Tekton Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package e2e +package task import ( "testing" @@ -20,19 +21,26 @@ import ( "github.com/AlecAivazis/survey/v2/terminal" "github.com/Netflix/go-expect" + "github.com/tektoncd/cli/test/e2e" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + tb "github.com/tektoncd/pipeline/test/builder" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/icmd" knativetest "knative.dev/pkg/test" ) +const ( + tePipelineGitResourceName = "skaffold-git" +) + func TestTaskStartE2E(t *testing.T) { t.Parallel() - c, namespace := Setup(t) - knativetest.CleanupOnInterrupt(func() { TearDown(t, c, namespace) }, t.Logf) - defer TearDown(t, c, namespace) + c, namespace := e2e.Setup(t) + knativetest.CleanupOnInterrupt(func() { e2e.TearDown(t, c, namespace) }, t.Logf) + defer e2e.TearDown(t, c, namespace) - tkn, err := NewTknRunner(namespace) + tkn, err := e2e.NewTknRunner(namespace) if err != nil { t.Fatalf("Error creating tknRunner %+v", err) } @@ -48,8 +56,8 @@ func TestTaskStartE2E(t *testing.T) { t.Run("Get list of Tasks from namespace "+namespace, func(t *testing.T) { res := tkn.Run("task", "list") - expected := ListAllTasksOutput(t, c, map[int]interface{}{ - 0: &TaskData{ + expected := e2e.ListAllTasksOutput(t, c, map[int]interface{}{ + 0: &e2e.TaskData{ Name: "read-task", }, }) @@ -69,9 +77,9 @@ func TestTaskStartE2E(t *testing.T) { "true") vars := make(map[string]interface{}) - taskRunGeneratedName := GetTaskRunListWithName(c, "read-task").Items[0].Name + taskRunGeneratedName := e2e.GetTaskRunListWithName(c, "read-task").Items[0].Name vars["Taskrun"] = taskRunGeneratedName - expected := ProcessString(`(Taskrun started: {{.Taskrun}} + expected := e2e.ProcessString(`(Taskrun started: {{.Taskrun}} Waiting for logs to be available... .*)`, vars) @@ -85,8 +93,8 @@ Waiting for logs to be available... t.Run("Get list of TaskRuns from namespace "+namespace, func(t *testing.T) { res := tkn.Run("taskrun", "list") - expected := ListAllTaskRunsOutput(t, c, false, map[int]interface{}{ - 0: &TaskRunData{ + expected := e2e.ListAllTaskRunsOutput(t, c, false, map[int]interface{}{ + 0: &e2e.TaskRunData{ Name: "read-task-run-", Status: "Succeeded", }, @@ -100,7 +108,7 @@ Waiting for logs to be available... }) t.Run("Validate interactive task logs, with follow mode (-f) ", func(t *testing.T) { - RunInteractiveTests(t, namespace, tkn.Path(), &Prompt{ + e2e.RunInteractiveTests(t, namespace, tkn.Path(), &e2e.Prompt{ CmdArgs: []string{"task", "logs", "-f", "-n", namespace}, Procedure: func(c *expect.Console) error { if _, err := c.ExpectString("Select task:"); err != nil { @@ -127,8 +135,16 @@ Waiting for logs to be available... func CreateResource(t *testing.T, resource, namespace string) { t.Helper() - kubectl := NewKubectl(namespace) - res := kubectl.Run("apply", "-f", TestResourcePath(resource)) + kubectl := e2e.NewKubectl(namespace) + res := kubectl.Run("apply", "-f", e2e.TestResourcePath(resource)) time.Sleep(1 * time.Second) - Assert(t, res, icmd.Success) + e2e.Assert(t, res, icmd.Success) +} + +func getGitResource(rname string, namespace string) *v1alpha1.PipelineResource { + return tb.PipelineResource(rname, namespace, tb.PipelineResourceSpec( + v1alpha1.PipelineResourceTypeGit, + tb.PipelineResourceSpecParam("url", "https://github.com/GoogleContainerTools/skaffold"), + tb.PipelineResourceSpecParam("revision", "master"), + )) }