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

Skip some tests if KO_DOCKER_REPO is missing… #710

Merged
merged 1 commit into from
Apr 5, 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
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 = "true"
)

func ensureDockerRepo(t *testing.T) string {
fmt.Println("missingKoFatal", missingKoFatal)
repo, err := getDockerRepo()
if err != nil {
if missingKoFatal == "false" {
t.Skip("KO_DOCKER_REPO env variable is required")
}
t.Fatal("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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another beautiful file 💃