Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small e2e tests refactoring #1505

Merged
merged 3 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions test/embed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ const (
taskOutput = "do you want to build a snowman"
)

// TestTaskRun_EmbeddedResource is an integration test that will verify a very simple "hello world" TaskRun can be
// executed with an embedded resource spec.
func TestTaskRun_EmbeddedResource(t *testing.T) {
c, namespace := setup(t)
t.Parallel()

knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)

t.Logf("Creating Task and TaskRun in namespace %s", namespace)
if _, err := c.TaskClient.Create(getEmbeddedTask(namespace, []string{"/bin/sh", "-c", fmt.Sprintf("echo %s", taskOutput)})); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", embedTaskName, err)
}
if _, err := c.TaskRunClient.Create(getEmbeddedTaskRun(namespace)); err != nil {
t.Fatalf("Failed to create TaskRun `%s`: %s", embedTaskRunName, err)
}

t.Logf("Waiting for TaskRun %s in namespace %s to complete", embedTaskRunName, namespace)
if err := WaitForTaskRunState(c, embedTaskRunName, TaskRunSucceed(embedTaskRunName), "TaskRunSuccess"); err != nil {
t.Errorf("Error waiting for TaskRun %s to finish: %s", embedTaskRunName, err)
}

// TODO(#127) Currently we have no reliable access to logs from the TaskRun so we'll assume successful
// completion of the TaskRun means the TaskRun did what it was intended.
}

func getEmbeddedTask(namespace string, args []string) *v1alpha1.Task {
return tb.Task(embedTaskName, namespace,
tb.TaskSpec(
Expand Down Expand Up @@ -62,29 +88,3 @@ func getEmbeddedTaskRun(namespace string) *v1alpha1.TaskRun {
),
tb.TaskRunTaskRef(embedTaskName)))
}

// TestTaskRun_EmbeddedResource is an integration test that will verify a very simple "hello world" TaskRun can be
// executed with an embedded resource spec.
func TestTaskRun_EmbeddedResource(t *testing.T) {
c, namespace := setup(t)
t.Parallel()

knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)

t.Logf("Creating Task and TaskRun in namespace %s", namespace)
if _, err := c.TaskClient.Create(getEmbeddedTask(namespace, []string{"/bin/sh", "-c", fmt.Sprintf("echo %s", taskOutput)})); err != nil {
t.Fatalf("Failed to create Task `%s`: %s", embedTaskName, err)
}
if _, err := c.TaskRunClient.Create(getEmbeddedTaskRun(namespace)); err != nil {
t.Fatalf("Failed to create TaskRun `%s`: %s", embedTaskRunName, err)
}

t.Logf("Waiting for TaskRun %s in namespace %s to complete", embedTaskRunName, namespace)
if err := WaitForTaskRunState(c, embedTaskRunName, TaskRunSucceed(embedTaskRunName), "TaskRunSuccess"); err != nil {
t.Errorf("Error waiting for TaskRun %s to finish: %s", embedTaskRunName, err)
}

// TODO(#127) Currently we have no reliable access to logs from the TaskRun so we'll assume successful
// completion of the TaskRun means the TaskRun did what it was intended.
}
50 changes: 26 additions & 24 deletions test/git_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,36 @@ func TestGitPipelineRun(t *testing.T) {

for _, revision := range revisions {

c, namespace := setup(t)
knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)

t.Logf("Creating Git PipelineResource %s", gitSourceResourceName)
if _, err := c.PipelineResourceClient.Create(getGitPipelineResource(namespace, revision)); err != nil {
t.Fatalf("Failed to create Pipeline Resource `%s`: %s", gitSourceResourceName, err)
}
t.Run(revision, func(t *testing.T) {
c, namespace := setup(t)
knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer tearDown(t, c, namespace)

t.Logf("Creating Git PipelineResource %s", gitSourceResourceName)
if _, err := c.PipelineResourceClient.Create(getGitPipelineResource(namespace, revision)); err != nil {
t.Fatalf("Failed to create Pipeline Resource `%s`: %s", gitSourceResourceName, err)
}

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

t.Logf("Creating Pipeline %s", gitTestPipelineName)
if _, err := c.PipelineClient.Create(getGitCheckPipeline(namespace)); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", gitTestPipelineName, err)
}
t.Logf("Creating Pipeline %s", gitTestPipelineName)
if _, err := c.PipelineClient.Create(getGitCheckPipeline(namespace)); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", gitTestPipelineName, err)
}

t.Logf("Creating PipelineRun %s", gitTestPipelineRunName)
if _, err := c.PipelineRunClient.Create(getGitCheckPipelineRun(namespace)); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", gitTestPipelineRunName, err)
}
t.Logf("Creating PipelineRun %s", gitTestPipelineRunName)
if _, err := c.PipelineRunClient.Create(getGitCheckPipelineRun(namespace)); err != nil {
t.Fatalf("Failed to create Pipeline `%s`: %s", gitTestPipelineRunName, err)
}

if err := WaitForPipelineRunState(c, gitTestPipelineRunName, timeout, PipelineRunSucceed(gitTestPipelineRunName), "PipelineRunCompleted"); err != nil {
t.Errorf("Error waiting for PipelineRun %s to finish: %s", gitTestPipelineRunName, err)
t.Fatalf("PipelineRun execution failed")
}
if err := WaitForPipelineRunState(c, gitTestPipelineRunName, timeout, PipelineRunSucceed(gitTestPipelineRunName), "PipelineRunCompleted"); err != nil {
t.Errorf("Error waiting for PipelineRun %s to finish: %s", gitTestPipelineRunName, err)
t.Fatalf("PipelineRun execution failed")
}
})
}
}

Expand Down
108 changes: 54 additions & 54 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,60 +43,6 @@ const (
revision = "1c9d566ecd13535f93789595740f20932f655905"
)

func getGitResource(namespace string) *v1alpha1.PipelineResource {
return tb.PipelineResource(kanikoGitResourceName, namespace, tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeGit,
tb.PipelineResourceSpecParam("Url", "https://github.com/GoogleContainerTools/kaniko"),
tb.PipelineResourceSpecParam("Revision", revision),
))
}

func getImageResource(namespace, repo string) *v1alpha1.PipelineResource {
return tb.PipelineResource(kanikoImageResourceName, namespace, tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeImage,
tb.PipelineResourceSpecParam("url", repo),
))
}

func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
taskSpecOps := []tb.TaskSpecOp{
tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
tb.TaskOutputs(tb.OutputsResource("builtImage", v1alpha1.PipelineResourceTypeImage)),
}
stepOps := []tb.StepOp{
tb.StepArgs(
"--dockerfile=/workspace/gitsource/integration/dockerfiles/Dockerfile_test_label",
fmt.Sprintf("--destination=%s", repo),
"--context=/workspace/gitsource",
"--oci-layout-path=/workspace/output/builtImage",
),
}
if withSecretConfig {
stepOps = append(stepOps,
tb.StepVolumeMount("kaniko-secret", "/secrets"),
tb.StepEnvVar("GOOGLE_APPLICATION_CREDENTIALS", "/secrets/config.json"),
)
taskSpecOps = append(taskSpecOps, tb.TaskVolume("kaniko-secret", tb.VolumeSource(corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "kaniko-secret",
},
})))
}
step := tb.Step("kaniko", "gcr.io/kaniko-project/executor:v0.13.0", stepOps...)
taskSpecOps = append(taskSpecOps, step)

return tb.Task(kanikoTaskName, namespace, tb.TaskSpec(taskSpecOps...))
}

func getTaskRun(namespace string) *v1alpha1.TaskRun {
return tb.TaskRun(kanikoTaskRunName, namespace, tb.TaskRunSpec(
tb.TaskRunTaskRef(kanikoTaskName),
tb.TaskRunTimeout(2*time.Minute),
tb.TaskRunInputs(tb.TaskRunInputsResource("gitsource", tb.TaskResourceBindingRef(kanikoGitResourceName))),
tb.TaskRunOutputs(tb.TaskRunOutputsResource("builtImage", tb.TaskResourceBindingRef(kanikoImageResourceName))),
))
}

// TestTaskRun is an integration test that will verify a TaskRun using kaniko
func TestKanikoTaskRun(t *testing.T) {
repo := ensureDockerRepo(t)
Expand Down Expand Up @@ -174,6 +120,60 @@ func TestKanikoTaskRun(t *testing.T) {
}
}

func getGitResource(namespace string) *v1alpha1.PipelineResource {
return tb.PipelineResource(kanikoGitResourceName, namespace, tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeGit,
tb.PipelineResourceSpecParam("Url", "https://github.com/GoogleContainerTools/kaniko"),
tb.PipelineResourceSpecParam("Revision", revision),
))
}

func getImageResource(namespace, repo string) *v1alpha1.PipelineResource {
return tb.PipelineResource(kanikoImageResourceName, namespace, tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeImage,
tb.PipelineResourceSpecParam("url", repo),
))
}

func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
taskSpecOps := []tb.TaskSpecOp{
tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
tb.TaskOutputs(tb.OutputsResource("builtImage", v1alpha1.PipelineResourceTypeImage)),
}
stepOps := []tb.StepOp{
tb.StepArgs(
"--dockerfile=/workspace/gitsource/integration/dockerfiles/Dockerfile_test_label",
fmt.Sprintf("--destination=%s", repo),
"--context=/workspace/gitsource",
"--oci-layout-path=/workspace/output/builtImage",
),
}
if withSecretConfig {
stepOps = append(stepOps,
tb.StepVolumeMount("kaniko-secret", "/secrets"),
tb.StepEnvVar("GOOGLE_APPLICATION_CREDENTIALS", "/secrets/config.json"),
)
taskSpecOps = append(taskSpecOps, tb.TaskVolume("kaniko-secret", tb.VolumeSource(corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "kaniko-secret",
},
})))
}
step := tb.Step("kaniko", "gcr.io/kaniko-project/executor:v0.13.0", stepOps...)
taskSpecOps = append(taskSpecOps, step)

return tb.Task(kanikoTaskName, namespace, tb.TaskSpec(taskSpecOps...))
}

func getTaskRun(namespace string) *v1alpha1.TaskRun {
return tb.TaskRun(kanikoTaskRunName, namespace, tb.TaskRunSpec(
tb.TaskRunTaskRef(kanikoTaskName),
tb.TaskRunTimeout(2*time.Minute),
tb.TaskRunInputs(tb.TaskRunInputsResource("gitsource", tb.TaskResourceBindingRef(kanikoGitResourceName))),
tb.TaskRunOutputs(tb.TaskRunOutputsResource("builtImage", tb.TaskResourceBindingRef(kanikoImageResourceName))),
))
}

func getRemoteDigest(image string) (string, error) {
ref, err := name.ParseReference(image, name.WeakValidation)
if err != nil {
Expand Down