Skip to content

Commit

Permalink
Skip some tests if KO_DOCKER_REPO is missing and explicitely asked for…
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

To skip those tests instead of failing, you need to provide the
following arguments to go test command :
`-ldflags '-X github.com/tektoncd/pipeline/test.missingKoFatal=false'`

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Apr 3, 2019
1 parent a669012 commit edbae90
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
13 changes: 3 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,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()
Expand All @@ -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)
}

Expand Down Expand Up @@ -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(
Expand Down
17 changes: 1 addition & 16 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
50 changes: 50 additions & 0 deletions test/ko_test.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit edbae90

Please sign in to comment.