-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial e2e for local source upload (Waiter).
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
apiVersion: shipwright.io/v1alpha1 | ||
kind: Build | ||
metadata: | ||
name: buildah-golang-build-local-source-upload | ||
spec: | ||
source: | ||
url: https://github.com/shipwright-io/sample-go | ||
contextDir: docker-build | ||
strategy: | ||
name: buildah | ||
kind: ClusterBuildStrategy | ||
dockerfile: Dockerfile | ||
output: | ||
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
apiVersion: shipwright.io/v1alpha1 | ||
kind: BuildRun | ||
metadata: | ||
name: buildah-golang-local-source-upload | ||
spec: | ||
buildRef: | ||
name: buildah-local-source-upload | ||
sources: | ||
- name: local-copy | ||
type: LocalCopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e_test | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" | ||
"github.com/shipwright-io/build/test/utils" | ||
) | ||
|
||
var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() { | ||
var ( | ||
testID string | ||
build *buildv1alpha1.Build | ||
buildRun *buildv1alpha1.BuildRun | ||
) | ||
|
||
AfterEach(func() { | ||
if buildRun != nil { | ||
testBuild.DeleteBR(buildRun.Name) | ||
buildRun = nil | ||
} | ||
|
||
if build != nil { | ||
testBuild.DeleteBuild(build.Name) | ||
build = nil | ||
} | ||
}) | ||
|
||
Context("when LocalCopy BuildSource is defined", func() { | ||
BeforeEach(func() { | ||
testID = generateTestID("local-copy") | ||
build = createBuild( | ||
testBuild, | ||
testID, | ||
"test/data/build_buildah_cr_local_source_upload.yaml", | ||
) | ||
}) | ||
|
||
It("should generate LocalCopy TaskRun, using the waiter", func() { | ||
var err error | ||
buildRun, err = buildRunTestData( | ||
testBuild.Namespace, | ||
testID, | ||
"test/data/buildrun_buildah_cr_local_source_upload.yaml", | ||
) | ||
Expect(err).ToNot(HaveOccurred(), "Error retrieving buildrun test data") | ||
|
||
validateWaiterBuildRun(testBuild, buildRun) | ||
}) | ||
}) | ||
}) | ||
|
||
func getBuildRunStatus(name types.NamespacedName) *corev1.ConditionStatus { | ||
testBuildRun, err := testBuild.LookupBuildRun(name) | ||
Expect(err).ToNot(HaveOccurred(), "Error retrieving the BuildRun") | ||
|
||
if len(testBuildRun.Status.Conditions) == 0 { | ||
return nil | ||
} | ||
return &testBuildRun.Status.GetCondition(buildv1alpha1.Succeeded).Status | ||
} | ||
|
||
// validateWaiterBuildRun assert the BuildRun informed will fail, since Waiter's timeout is reached | ||
// and it causes the actual build process to fail as well. | ||
func validateWaiterBuildRun(testBuild *utils.TestBuild, testBuildRun *buildv1alpha1.BuildRun) { | ||
// making sure the BuildRun has been created on the cluster | ||
if _, err := testBuild.GetBR(testBuildRun.Name); err != nil { | ||
Expect(testBuild.CreateBR(testBuildRun)). | ||
ToNot(HaveOccurred(), "Failed to create BuildRun") | ||
} | ||
|
||
falseCondition := corev1.ConditionFalse | ||
unknownCondition := corev1.ConditionUnknown | ||
|
||
buildRunName := types.NamespacedName{Namespace: testBuild.Namespace, Name: testBuildRun.Name} | ||
|
||
// making sure the taskrun is schedule and becomes a pod, since the build-controller will transit | ||
// the object status from empty to unknown, when the actual build starts | ||
Eventually(func() *corev1.ConditionStatus { | ||
status := getBuildRunStatus(buildRunName) | ||
Logf("BuildRun '%s' status '%v'...", buildRunName, status) | ||
return status | ||
}, time.Duration(60*time.Second), 3*time.Second). | ||
Should(Equal(&unknownCondition), "BuildRun should reach unknown condition") | ||
|
||
// asserting the waiter step will end up in timeout, in other words, it ends as failed | ||
Eventually(func() *corev1.ConditionStatus { | ||
status := getBuildRunStatus(buildRunName) | ||
Expect(status).ToNot(BeNil()) | ||
Logf("BuildRun '%s' status '%s'...", buildRunName, *status) | ||
return status | ||
}, time.Duration(90*time.Second), 10*time.Second). | ||
Should(Equal(&falseCondition), "BuildRun should end up in timeout") | ||
} |