Skip to content

Commit

Permalink
Skip some tests if KO_DOCKER_REPO is missing…
Browse files Browse the repository at this point in the history
… instead of "hard" failing, we could just skip it as it doesn't meet
the requirements. Impacted tests :

- TestHelmDeployPipelineRun
- TestKanikoTaskRun

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Apr 2, 2019
1 parent 7a48421 commit 7fa00ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
16 changes: 6 additions & 10 deletions test/helm_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package test
import (
"fmt"
"net/http"
"os"
"testing"
"time"

Expand Down Expand Up @@ -51,6 +50,10 @@ 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, err := getDockerRepo()
if err != nil {
t.Skip("KO_DOCKER_REPO env variable is required")
}
c, namespace := setup(t)
setupClusterBindingForHelm(c, t, namespace)
t.Parallel()
Expand All @@ -64,7 +67,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)
}

Expand Down Expand Up @@ -150,14 +153,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(
Expand Down
7 changes: 3 additions & 4 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ func getTaskRun(namespace string) *v1alpha1.TaskRun {

// TestTaskRun is an integration test that will verify a TaskRun using kaniko
func TestKanikoTaskRun(t *testing.T) {
c, namespace := setup(t)
t.Parallel()

repo, err := getDockerRepo()
if err != nil {
t.Errorf("Expected to get docker repo")
t.Skip("KO_DOCKER_REPO env variable is required")
}
c, namespace := setup(t)
t.Parallel()

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

0 comments on commit 7fa00ae

Please sign in to comment.