diff --git a/test/helm_task_test.go b/test/helm_task_test.go index 655dffda363..800ed1f67a4 100644 --- a/test/helm_task_test.go +++ b/test/helm_task_test.go @@ -18,7 +18,6 @@ package test import ( "fmt" "net/http" - "os" "testing" "time" @@ -51,6 +50,7 @@ var ( // TestHelmDeployPipelineRun is an integration test that will verify a pipeline build an image // and then using helm to deploy it func TestHelmDeployPipelineRun(t *testing.T) { + repo := ensureDockerRepo(t) c, namespace := setup(t) setupClusterBindingForHelm(c, t, namespace) t.Parallel() @@ -64,7 +64,7 @@ func TestHelmDeployPipelineRun(t *testing.T) { } t.Logf("Creating Image PipelineResource %s", sourceImageName) - if _, err := c.PipelineResourceClient.Create(getHelmImageResource(t, namespace)); err != nil { + if _, err := c.PipelineResourceClient.Create(getHelmImageResource(namespace, repo)); err != nil { t.Fatalf("Failed to create Pipeline Resource `%s`: %s", sourceImageName, err) } @@ -150,14 +150,7 @@ func getGoHelloworldGitResource(namespace string) *v1alpha1.PipelineResource { )) } -func getHelmImageResource(t *testing.T, namespace string) *v1alpha1.PipelineResource { - // according to knative/test-infra readme (https://github.com/knative/test-infra/blob/13055d769cc5e1756e605fcb3bcc1c25376699f1/scripts/README.md) - // the KO_DOCKER_REPO will be set with according to the project where the cluster is created - // it is used here to dynamically get the docker registry to push the image to - dockerRepo := os.Getenv("KO_DOCKER_REPO") - if dockerRepo == "" { - t.Fatalf("KO_DOCKER_REPO env variable is required") - } +func getHelmImageResource(namespace, dockerRepo string) *v1alpha1.PipelineResource { imageName := fmt.Sprintf("%s/%s", dockerRepo, names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(sourceImageName)) return tb.PipelineResource(sourceImageName, namespace, tb.PipelineResourceSpec( diff --git a/test/kaniko_task_test.go b/test/kaniko_task_test.go index a4428154184..f30cc42c91d 100644 --- a/test/kaniko_task_test.go +++ b/test/kaniko_task_test.go @@ -51,17 +51,6 @@ func getGitResource(namespace string) *v1alpha1.PipelineResource { )) } -func getDockerRepo() (string, error) { - // according to knative/test-infra readme (https://github.com/knative/test-infra/blob/13055d769cc5e1756e605fcb3bcc1c25376699f1/scripts/README.md) - // the KO_DOCKER_REPO will be set with according to the project where the cluster is created - // it is used here to dynamically get the docker registry to push the image to - dockerRepo := os.Getenv("KO_DOCKER_REPO") - if dockerRepo == "" { - return "", fmt.Errorf("KO_DOCKER_REPO env variable is required") - } - return fmt.Sprintf("%s/kanikotasktest", dockerRepo), nil -} - 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") @@ -123,14 +112,10 @@ func getTaskRun(namespace string) *v1alpha1.TaskRun { // TestTaskRun is an integration test that will verify a TaskRun using kaniko func TestKanikoTaskRun(t *testing.T) { + repo := ensureDockerRepo(t) c, namespace := setup(t) t.Parallel() - repo, err := getDockerRepo() - if err != nil { - t.Errorf("Expected to get docker repo") - } - knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf) defer tearDown(t, c, namespace) diff --git a/test/ko_test.go b/test/ko_test.go new file mode 100644 index 00000000000..7fe1a7cd1e0 --- /dev/null +++ b/test/ko_test.go @@ -0,0 +1,50 @@ +// +build e2e + +/* +Copyright 2019 Knative Authors LLC +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package test + +import ( + "fmt" + "os" + "testing" +) + +var ( + // Wether missing KO_DOCKER_REPO environment variable should be fatal or not + missingKoFatal = "yes" +) + +func ensureDockerRepo(t *testing.T) string { + fmt.Println("missingKoFatal", missingKoFatal) + repo, err := getDockerRepo() + if err != nil { + if missingKoFatal == "yes" { + t.Fatal("KO_DOCKER_REPO env variable is required") + } + t.Skip("KO_DOCKER_REPO env variable is required") + } + return repo +} + +func getDockerRepo() (string, error) { + // according to knative/test-infra readme (https://github.com/knative/test-infra/blob/13055d769cc5e1756e605fcb3bcc1c25376699f1/scripts/README.md) + // the KO_DOCKER_REPO will be set with according to the project where the cluster is created + // it is used here to dynamically get the docker registry to push the image to + dockerRepo := os.Getenv("KO_DOCKER_REPO") + if dockerRepo == "" { + return "", fmt.Errorf("KO_DOCKER_REPO env variable is required") + } + return fmt.Sprintf("%s/kanikotasktest", dockerRepo), nil +}