Skip to content

Commit

Permalink
Introduce v1beta1 e2e go tests 📥
Browse files Browse the repository at this point in the history
… and move v1alpha1 e2e go tests in their own package.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Mar 23, 2020
1 parent c84b03a commit ef22c6c
Show file tree
Hide file tree
Showing 58 changed files with 6,087 additions and 602 deletions.
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/test"
tb "github.com/tektoncd/pipeline/test/builder"
test "github.com/tektoncd/pipeline/test/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
taskrunresources "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/pkg/system"
"github.com/tektoncd/pipeline/test"
tb "github.com/tektoncd/pipeline/test/builder"
"github.com/tektoncd/pipeline/test/names"
test "github.com/tektoncd/pipeline/test/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ktesting "k8s.io/client-go/testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/test"
tb "github.com/tektoncd/pipeline/test/builder"
test "github.com/tektoncd/pipeline/test/v1alpha1"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
corev1 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/test"
tb "github.com/tektoncd/pipeline/test/builder"
test "github.com/tektoncd/pipeline/test/v1alpha1"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
corev1 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources/cloudevent"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/pkg/system"
"github.com/tektoncd/pipeline/test"
tb "github.com/tektoncd/pipeline/test/builder"
"github.com/tektoncd/pipeline/test/names"
test "github.com/tektoncd/pipeline/test/v1alpha1"
corev1 "k8s.io/api/core/v1"
k8sapierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/timeout_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/test"
tb "github.com/tektoncd/pipeline/test/builder"
test "github.com/tektoncd/pipeline/test/v1alpha1"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
corev1 "k8s.io/api/core/v1"
Expand Down
201 changes: 142 additions & 59 deletions test/artifact_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"time"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
"github.com/tektoncd/pipeline/pkg/artifacts"
tb "github.com/tektoncd/pipeline/test/builder"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -66,28 +68,44 @@ func TestStorageBucketPipelineRun(t *testing.T) {
defer deleteBucketSecret(c, t, namespace)

t.Logf("Creating GCS bucket %s", bucketName)
createbuckettask := tb.Task("createbuckettask", namespace, tb.TaskSpec(
tb.TaskVolume("bucket-secret-volume", tb.VolumeSource(corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: bucketSecretName,
},
})),
tb.Step("google/cloud-sdk:alpine", tb.StepName("step1"),
tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", fmt.Sprintf("gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil mb gs://%s", bucketName)),
tb.StepVolumeMount("bucket-secret-volume", fmt.Sprintf("/var/secret/%s", bucketSecretName)),
tb.StepEnvVar("CREDENTIALS", fmt.Sprintf("/var/secret/%s/%s", bucketSecretName, bucketSecretKey)),
),
),
)
createbuckettask := &v1beta1.Task{
ObjectMeta: metav1.ObjectMeta{Name: "createbuckettask", Namespace: namespace},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Name: "step1",
Image: "google/cloud-sdk:alpine",
Command: []string{"/bin/bash"},
Args: []string{"-c", fmt.Sprintf("gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil mb gs://%s", bucketName)},
VolumeMounts: []corev1.VolumeMount{{
Name: "bucket-secret-volume",
MountPath: fmt.Sprintf("/var/secret/%s", bucketSecretName),
}},
Env: []corev1.EnvVar{{
Name: "CREDENTIALS", Value: fmt.Sprintf("/var/secret/%s/%s", bucketSecretName, bucketSecretKey),
}},
}}},
Volumes: []corev1.Volume{{
Name: "bucket-secret-volume",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: bucketSecretName,
},
},
}},
},
}

t.Logf("Creating Task %s", "createbuckettask")
if _, err := c.TaskClient.Create(createbuckettask); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", "createbuckettask", err)
}

createbuckettaskrun := tb.TaskRun("createbuckettaskrun", namespace,
tb.TaskRunSpec(tb.TaskRunTaskRef("createbuckettask")))
createbuckettaskrun := &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{Name: "createbuckettaskrun", Namespace: namespace},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{Name: "createbuckettask"},
},
}

t.Logf("Creating TaskRun %s", "createbuckettaskrun")
if _, err := c.TaskRunClient.Create(createbuckettaskrun); err != nil {
Expand Down Expand Up @@ -129,48 +147,97 @@ func TestStorageBucketPipelineRun(t *testing.T) {
}

t.Logf("Creating Task %s", addFileTaskName)
addFileTask := tb.Task(addFileTaskName, namespace, tb.TaskSpec(
tb.TaskInputs(tb.InputsResource(helloworldResourceName, v1alpha1.PipelineResourceTypeGit)),
tb.TaskOutputs(tb.OutputsResource(helloworldResourceName, v1alpha1.PipelineResourceTypeGit)),
tb.Step("ubuntu", tb.StepName("addfile"), tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", "'#!/bin/bash\necho hello' > /workspace/helloworldgit/newfile"),
),
tb.Step("ubuntu", tb.StepName("make-executable"), tb.StepCommand("chmod"),
tb.StepArgs("+x", "/workspace/helloworldgit/newfile")),
))
addFileTask := &v1beta1.Task{
ObjectMeta: metav1.ObjectMeta{Name: addFileTaskName, Namespace: namespace},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Container: corev1.Container{
Name: "addfile", Image: "ubuntu",
},
Script: "echo '#!/bin/bash\necho hello' > /workspace/helloworldgit/newfile",
}, {
Container: corev1.Container{
Name: "make-executable", Image: "ubuntu",
},
Script: "chmod +x /workspace/helloworldgit/newfile",
}},
Resources: &v1beta1.TaskResources{
Inputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{
Name: helloworldResourceName, Type: resourcev1alpha1.PipelineResourceTypeGit,
}}},
Outputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{
Name: helloworldResourceName, Type: resourcev1alpha1.PipelineResourceTypeGit,
}}},
},
},
}
if _, err := c.TaskClient.Create(addFileTask); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", addFileTaskName, err)
}

t.Logf("Creating Task %s", runFileTaskName)
readFileTask := tb.Task(runFileTaskName, namespace, tb.TaskSpec(
tb.TaskInputs(tb.InputsResource(helloworldResourceName, v1alpha1.PipelineResourceTypeGit)),
tb.Step("ubuntu", tb.StepName("runfile"), tb.StepCommand("/workspace/helloworld/newfile")),
))
readFileTask := &v1beta1.Task{
ObjectMeta: metav1.ObjectMeta{Name: runFileTaskName, Namespace: namespace},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Name: "runfile", Image: "ubuntu",
Command: []string{"/workspace/hellowrld/newfile"},
}}},
Resources: &v1beta1.TaskResources{
Inputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{
Name: helloworldResourceName, Type: resourcev1alpha1.PipelineResourceTypeGit,
}}},
},
},
}
if _, err := c.TaskClient.Create(readFileTask); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", runFileTaskName, err)
}

t.Logf("Creating Pipeline %s", bucketTestPipelineName)
bucketTestPipeline := tb.Pipeline(bucketTestPipelineName, namespace, tb.PipelineSpec(
tb.PipelineDeclaredResource("source-repo", "git"),
tb.PipelineTask("addfile", addFileTaskName,
tb.PipelineTaskInputResource("helloworldgit", "source-repo"),
tb.PipelineTaskOutputResource("helloworldgit", "source-repo"),
),
tb.PipelineTask("runfile", runFileTaskName,
tb.PipelineTaskInputResource("helloworldgit", "source-repo", tb.From("addfile")),
),
))
bucketTestPipeline := &v1beta1.Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: bucketTestPipelineName, Namespace: namespace},
Spec: v1beta1.PipelineSpec{
Resources: []v1beta1.PipelineDeclaredResource{{
Name: "source-repo", Type: resourcev1alpha1.PipelineResourceTypeGit,
}},
Tasks: []v1beta1.PipelineTask{{
Name: "addfile",
TaskRef: &v1beta1.TaskRef{Name: addFileTaskName},
Resources: &v1beta1.PipelineTaskResources{
Inputs: []v1beta1.PipelineTaskInputResource{{
Name: "helloworldgit", Resource: "source-repo",
}},
Outputs: []v1beta1.PipelineTaskOutputResource{{
Name: "helloworldgit", Resource: "source-rep",
}},
},
}, {
Name: "runfile",
TaskRef: &v1beta1.TaskRef{Name: runFileTaskName},
Resources: &v1beta1.PipelineTaskResources{
Inputs: []v1beta1.PipelineTaskInputResource{{
Name: "helloworldgit", Resource: "source-repo",
}},
},
}},
},
}
if _, err := c.PipelineClient.Create(bucketTestPipeline); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", bucketTestPipelineName, err)
}

t.Logf("Creating PipelineRun %s", bucketTestPipelineRunName)
bucketTestPipelineRun := tb.PipelineRun(bucketTestPipelineRunName, namespace, tb.PipelineRunSpec(
bucketTestPipelineName,
tb.PipelineRunResourceBinding("source-repo", tb.PipelineResourceBindingRef(helloworldResourceName)),
))
bucketTestPipelineRun := &v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{Name: bucketTestPipelineRunName, Namespace: namespace},
Spec: v1beta1.PipelineRunSpec{
PipelineRef: &v1beta1.PipelineRef{Name: bucketTestPipelineName},
Resources: []v1beta1.PipelineResourceBinding{{
Name: "source-repo",
ResourceRef: &v1beta1.PipelineResourceRef{Name: helloworldResourceName},
}},
},
}
if _, err := c.PipelineRunClient.Create(bucketTestPipelineRun); err != nil {
t.Fatalf("Failed to create PipelineRun `%s`: %s", bucketTestPipelineRunName, err)
}
Expand Down Expand Up @@ -232,28 +299,44 @@ func resetConfigMap(t *testing.T, c *clients, namespace, configName string, valu
}

func runTaskToDeleteBucket(c *clients, t *testing.T, namespace, bucketName, bucketSecretName, bucketSecretKey string) {
deletelbuckettask := tb.Task("deletelbuckettask", namespace, tb.TaskSpec(
tb.TaskVolume("bucket-secret-volume", tb.VolumeSource(corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: bucketSecretName,
},
})),
tb.Step("google/cloud-sdk:alpine", tb.StepName("step1"),
tb.StepCommand("/bin/bash"),
tb.StepArgs("-c", fmt.Sprintf("gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil rm -r gs://%s", bucketName)),
tb.StepVolumeMount("bucket-secret-volume", fmt.Sprintf("/var/secret/%s", bucketSecretName)),
tb.StepEnvVar("CREDENTIALS", fmt.Sprintf("/var/secret/%s/%s", bucketSecretName, bucketSecretKey)),
),
),
)
deletelbuckettask := &v1beta1.Task{
ObjectMeta: metav1.ObjectMeta{Name: "deletelbuckettask", Namespace: namespace},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Name: "step1",
Image: "google/cloud-sdk:alpine",
Command: []string{"/bin/bash"},
Args: []string{"-c", fmt.Sprintf("gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil rm -r gs://%s", bucketName)},
VolumeMounts: []corev1.VolumeMount{{
Name: "bucket-secret-volume",
MountPath: fmt.Sprintf("/var/secret/%s", bucketSecretName),
}},
Env: []corev1.EnvVar{{
Name: "CREDENTIALS", Value: fmt.Sprintf("/var/secret/%s/%s", bucketSecretName, bucketSecretKey),
}},
}}},
Volumes: []corev1.Volume{{
Name: "bucket-secret-volume",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: bucketSecretName,
},
},
}},
},
}

t.Logf("Creating Task %s", "deletelbuckettask")
if _, err := c.TaskClient.Create(deletelbuckettask); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", "deletelbuckettask", err)
}

deletelbuckettaskrun := tb.TaskRun("deletelbuckettaskrun", namespace,
tb.TaskRunSpec(tb.TaskRunTaskRef("deletelbuckettask")))
deletelbuckettaskrun := &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{Name: "deletelbuckettaskrun", Namespace: namespace},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{Name: "deletelbuckettask"},
},
}

t.Logf("Creating TaskRun %s", "deletelbuckettaskrun")
if _, err := c.TaskRunClient.Create(deletelbuckettaskrun); err != nil {
Expand Down
42 changes: 30 additions & 12 deletions test/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"sync"
"testing"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
tb "github.com/tektoncd/pipeline/test/builder"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
knativetest "knative.dev/pkg/test"
)
Expand Down Expand Up @@ -52,9 +52,12 @@ func TestTaskRunPipelineRunCancel(t *testing.T) {
for _, tdd := range tds {
t.Run(tdd.name, func(t *testing.T) {
tdd := tdd
var pipelineTask = tb.PipelineTask("foo", "banana")
pipelineTask := v1beta1.PipelineTask{
Name: "foo",
TaskRef: &v1beta1.TaskRef{Name: "banana"},
}
if tdd.retries {
pipelineTask = tb.PipelineTask("foo", "banana", tb.Retries(1))
pipelineTask.Retries = 1
}

c, namespace := setup(t)
Expand All @@ -64,22 +67,37 @@ func TestTaskRunPipelineRunCancel(t *testing.T) {
defer tearDown(t, c, namespace)

t.Logf("Creating Task in namespace %s", namespace)
task := tb.Task("banana", namespace, tb.TaskSpec(
tb.Step("ubuntu", tb.StepCommand("/bin/bash"), tb.StepArgs("-c", "sleep 5000")),
))
task := &v1beta1.Task{
ObjectMeta: metav1.ObjectMeta{Name: "banana", Namespace: namespace},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Image: "ubuntu",
Command: []string{"/bin/bash"},
Args: []string{"-c", "sleep 5000"},
}}},
},
}
if _, err := c.TaskClient.Create(task); err != nil {
t.Fatalf("Failed to create Task `banana`: %s", err)
}

t.Logf("Creating Pipeline in namespace %s", namespace)
pipeline := tb.Pipeline("tomatoes", namespace,
tb.PipelineSpec(pipelineTask),
)
pipeline := &v1beta1.Pipeline{
ObjectMeta: metav1.ObjectMeta{Name: "tomatoes", Namespace: namespace},
Spec: v1beta1.PipelineSpec{
Tasks: []v1beta1.PipelineTask{pipelineTask},
},
}
if _, err := c.PipelineClient.Create(pipeline); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", "tomatoes", err)
}

pipelineRun := tb.PipelineRun("pear", namespace, tb.PipelineRunSpec(pipeline.Name))
pipelineRun := &v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{Name: "pear", Namespace: namespace},
Spec: v1beta1.PipelineRunSpec{
PipelineRef: &v1beta1.PipelineRef{Name: pipeline.Name},
},
}

t.Logf("Creating PipelineRun in namespace %s", namespace)
if _, err := c.PipelineRunClient.Create(pipelineRun); err != nil {
Expand Down Expand Up @@ -117,7 +135,7 @@ func TestTaskRunPipelineRunCancel(t *testing.T) {
t.Fatalf("Failed to get PipelineRun `%s`: %s", "pear", err)
}

pr.Spec.Status = v1alpha1.PipelineRunSpecStatusCancelled
pr.Spec.Status = v1beta1.PipelineRunSpecStatusCancelled
if _, err := c.PipelineRunClient.Update(pr); err != nil {
t.Fatalf("Failed to cancel PipelineRun `%s`: %s", "pear", err)
}
Expand Down
Loading

0 comments on commit ef22c6c

Please sign in to comment.