Skip to content

Commit

Permalink
Clean up e2e entrypoint_test.go
Browse files Browse the repository at this point in the history
- don't use test builders
- use busybox and script
- create TaskRun directly
- copy v1beta1 test to v1alpha1
  • Loading branch information
imjasonh committed Sep 10, 2020
1 parent a162a1d commit 8a32960
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 42 deletions.
38 changes: 13 additions & 25 deletions test/entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import (
knativetest "knative.dev/pkg/test"
)

const (
epTaskName = "ep-task"
epTaskRunName = "ep-task-run"
)
const epTaskRunName = "ep-task-run"

// TestEntrypointRunningStepsInOrder is an integration test that will
// verify attempt to the get the entrypoint of a container image
Expand All @@ -43,30 +40,21 @@ func TestEntrypointRunningStepsInOrder(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)

t.Logf("Creating Task and TaskRun in namespace %s", namespace)
task := &v1beta1.Task{
ObjectMeta: metav1.ObjectMeta{Name: epTaskName, Namespace: namespace},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Image: "ubuntu",
Args: []string{"-c", "sleep 3 && touch foo"},
}}, {Container: corev1.Container{
Image: "ubuntu",
Args: []string{"-c", "ls", "foo"},
}}},
},
}
if _, err := c.TaskClient.Create(task); err != nil {
t.Fatalf("Failed to create Task: %s", err)
}
taskRun := &v1beta1.TaskRun{
t.Logf("Creating TaskRun in namespace %s", namespace)
if _, err := c.TaskRunClient.Create(&v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{Name: epTaskRunName, Namespace: namespace},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{Name: epTaskName},
ServiceAccountName: "default",
TaskSpec: &v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Container: corev1.Container{Image: "busybox"},
Script: "sleep 3 && touch foo",
}, {
Container: corev1.Container{Image: "ubuntu"},
Script: "ls foo",
}},
},
},
}
if _, err := c.TaskRunClient.Create(taskRun); err != nil {
}); err != nil {
t.Fatalf("Failed to create TaskRun: %s", err)
}

Expand Down
37 changes: 20 additions & 17 deletions test/v1alpha1/entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ package test
import (
"testing"

tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"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"
)

const (
epTaskName = "ep-task"
epTaskRunName = "ep-task-run"
)
const epTaskRunName = "ep-task-run"

// TestEntrypointRunningStepsInOrder is an integration test that will
// verify attempt to the get the entrypoint of a container image
Expand All @@ -41,18 +41,21 @@ func TestEntrypointRunningStepsInOrder(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)

t.Logf("Creating Task and TaskRun in namespace %s", namespace)
task := tb.Task(epTaskName, tb.TaskSpec(
tb.Step("ubuntu", tb.StepArgs("-c", "sleep 3 && touch foo")),
tb.Step("ubuntu", tb.StepArgs("-c", "ls", "foo")),
))
if _, err := c.TaskClient.Create(task); err != nil {
t.Fatalf("Failed to create Task: %s", err)
}
taskRun := tb.TaskRun(epTaskRunName, tb.TaskRunSpec(
tb.TaskRunTaskRef(epTaskName), tb.TaskRunServiceAccountName("default"),
))
if _, err := c.TaskRunClient.Create(taskRun); err != nil {
t.Logf("Creating TaskRun in namespace %s", namespace)
if _, err := c.TaskRunClient.Create(&v1alpha1.TaskRun{
ObjectMeta: metav1.ObjectMeta{Name: epTaskRunName, Namespace: namespace},
Spec: v1alpha1.TaskRunSpec{
TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Container: corev1.Container{Image: "busybox"},
Script: "sleep 3 && touch foo",
}, {
Container: corev1.Container{Image: "ubuntu"},
Script: "ls foo",
}},
}},
},
}); err != nil {
t.Fatalf("Failed to create TaskRun: %s", err)
}

Expand Down

0 comments on commit 8a32960

Please sign in to comment.