From 5c049048ed65627362171aa47c9bdc5286834644 Mon Sep 17 00:00:00 2001
From: Vincent Demeester <vdemeest@redhat.com>
Date: Wed, 10 Apr 2019 17:24:15 +0200
Subject: [PATCH] Print Build finished instead of sucessful in nop

`nop` image/step used to be executed *only* when all the previous step
were done sucessfully. As we are not using init containers anymore,
this is not true, `nop` will always be executed even in case of
previous failure (after the others though).

Saying build successful is misleading, let's changed that to `finished`.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
---
 cmd/nop/main.go          |   2 +-
 test/kaniko_task_test.go | 137 +++++++++++++++++++--------------------
 2 files changed, 67 insertions(+), 72 deletions(-)

diff --git a/cmd/nop/main.go b/cmd/nop/main.go
index 31343ae727c..538a5947340 100644
--- a/cmd/nop/main.go
+++ b/cmd/nop/main.go
@@ -19,5 +19,5 @@ package main
 import "fmt"
 
 func main() {
-	fmt.Println("Build successful")
+	fmt.Println("Build finished")
 }
diff --git a/test/kaniko_task_test.go b/test/kaniko_task_test.go
index f30cc42c91d..37902894610 100644
--- a/test/kaniko_task_test.go
+++ b/test/kaniko_task_test.go
@@ -41,75 +41,8 @@ const (
 	kanikoTaskName     = "kanikotask"
 	kanikoTaskRunName  = "kanikotask-run"
 	kanikoResourceName = "go-example-git"
-	kanikoBuildOutput  = "Build successful"
 )
 
-func getGitResource(namespace string) *v1alpha1.PipelineResource {
-	return tb.PipelineResource(kanikoResourceName, namespace, tb.PipelineResourceSpec(
-		v1alpha1.PipelineResourceTypeGit,
-		tb.PipelineResourceSpecParam("Url", "https://github.com/pivotal-nader-ziada/gohelloworld"),
-	))
-}
-
-func createSecret(c *knativetest.KubeClient, namespace string) (bool, error) {
-	// when running e2e in cluster, this will not be set so just hop out early
-	file := os.Getenv("GCP_SERVICE_ACCOUNT_KEY_PATH")
-	if file == "" {
-		return false, nil
-	}
-
-	sec := &corev1.Secret{}
-	sec.Name = "kaniko-secret"
-	sec.Namespace = namespace
-
-	bs, err := ioutil.ReadFile(file)
-	if err != nil {
-		return false, fmt.Errorf("couldn't read kaniko secret json: %v", err)
-	}
-
-	sec.Data = map[string][]byte{
-		"config.json": bs,
-	}
-	_, err = c.Kube.CoreV1().Secrets(namespace).Create(sec)
-	return true, err
-}
-
-func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
-	taskSpecOps := []tb.TaskSpecOp{
-		tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
-	}
-	stepOps := []tb.ContainerOp{
-		tb.Args(
-			"--dockerfile=/workspace/gitsource/Dockerfile",
-			fmt.Sprintf("--destination=%s", repo),
-			"--context=/workspace/gitsource",
-		),
-	}
-	if withSecretConfig {
-		stepOps = append(stepOps,
-			tb.VolumeMount("kaniko-secret", "/secrets"),
-			tb.EnvVar("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", 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(kanikoResourceName))),
-	))
-}
-
 // TestTaskRun is an integration test that will verify a TaskRun using kaniko
 func TestKanikoTaskRun(t *testing.T) {
 	repo := ensureDockerRepo(t)
@@ -162,10 +95,6 @@ func TestKanikoTaskRun(t *testing.T) {
 	if err != nil {
 		t.Fatalf("Expected to get logs from pod %s: %v", podName, err)
 	}
-	// check the logs contain our success criteria
-	if !strings.Contains(logs, kanikoBuildOutput) {
-		t.Fatalf("Expected output %s from pod %s but got %s", kanikoBuildOutput, podName, logs)
-	}
 	// make sure the pushed digest matches the one we pushed
 	re := regexp.MustCompile("digest: (sha256:\\w+)")
 	match := re.FindStringSubmatch(logs)
@@ -233,3 +162,69 @@ func getRemoteDigest(image string) (string, error) {
 	}
 	return digest.String(), nil
 }
+
+func getGitResource(namespace string) *v1alpha1.PipelineResource {
+	return tb.PipelineResource(kanikoResourceName, namespace, tb.PipelineResourceSpec(
+		v1alpha1.PipelineResourceTypeGit,
+		tb.PipelineResourceSpecParam("Url", "https://github.com/pivotal-nader-ziada/gohelloworld"),
+	))
+}
+
+func createSecret(c *knativetest.KubeClient, namespace string) (bool, error) {
+	// when running e2e in cluster, this will not be set so just hop out early
+	file := os.Getenv("GCP_SERVICE_ACCOUNT_KEY_PATH")
+	if file == "" {
+		return false, nil
+	}
+
+	sec := &corev1.Secret{}
+	sec.Name = "kaniko-secret"
+	sec.Namespace = namespace
+
+	bs, err := ioutil.ReadFile(file)
+	if err != nil {
+		return false, fmt.Errorf("couldn't read kaniko secret json: %v", err)
+	}
+
+	sec.Data = map[string][]byte{
+		"config.json": bs,
+	}
+	_, err = c.Kube.CoreV1().Secrets(namespace).Create(sec)
+	return true, err
+}
+
+func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
+	taskSpecOps := []tb.TaskSpecOp{
+		tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
+	}
+	stepOps := []tb.ContainerOp{
+		tb.Args(
+			"--dockerfile=/workspace/gitsource/Dockerfile",
+			fmt.Sprintf("--destination=%s", repo),
+			"--context=/workspace/gitsource",
+		),
+	}
+	if withSecretConfig {
+		stepOps = append(stepOps,
+			tb.VolumeMount("kaniko-secret", "/secrets"),
+			tb.EnvVar("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", 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(kanikoResourceName))),
+	))
+}