Skip to content

Commit

Permalink
add e2e test for v1beta1-localsource
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvajagtap committed Nov 7, 2023
1 parent 31e7555 commit eab8062
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ The `Build` definition supports the following fields:

A `Build` resource can specify a Git repository or bundle image source, together with other parameters like:

- `source.type` - Specify the type of the data-source. Currently, the supported types are "Git", "OCI", and "Local".
- `source.git.url` - Specify the source location using a Git repository.
- `source.git.cloneSecret` - For private repositories or registries, the name references a secret in the namespace that contains the SSH private key or Docker access credentials, respectively.
- `source.git.revision` - A specific revision to select from the source repository, this can be a commit, tag or branch name. If not defined, it will fallback to the Git repository default branch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ metadata:
spec:
build:
name: buildah-local-source-upload
sources:
- name: local-copy
source:
local:
name: local-copy
type: Local
104 changes: 104 additions & 0 deletions test/e2e/v1beta1/e2e_local_source_upload_test.go
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/v2"
. "github.com/onsi/gomega"

"k8s.io/apimachinery/pkg/types"

buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
utils "github.com/shipwright-io/build/test/utils/v1beta1"
)

var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() {
var (
testID string
build *buildv1beta1.Build
buildRun *buildv1beta1.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/v1beta1/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/v1beta1/buildrun_buildah_cr_local_source_upload.yaml",
)
Expect(err).ToNot(HaveOccurred(), "Error retrieving buildrun test data")

validateWaiterBuildRun(testBuild, buildRun)
})
})
})

func getBuildRunStatusCondition(name types.NamespacedName) *buildv1beta1.Condition {
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(buildv1beta1.Succeeded)
}

// 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 *buildv1beta1.BuildRun) {
err := testBuild.CreateBR(testBuildRun)
Expect(err).ToNot(HaveOccurred(), "Failed to create BuildRun")

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 being executed
Eventually(func() bool {
condition := getBuildRunStatusCondition(buildRunName)
if condition == nil {
return false
}
Logf("BuildRun %q status %q...", buildRunName, condition.Status)
return condition.Reason == "Running"
}, time.Duration(1100*getTimeoutMultiplier())*time.Second, 5*time.Second).
Should(BeTrue(), "BuildRun should start running")

// asserting the waiter step will end up in timeout, in other words, the build is terminated with
// the reason "failed"
Eventually(func() string {
condition := getBuildRunStatusCondition(buildRunName)
Expect(condition).ToNot(BeNil())
Logf("BuildRun %q condition %v...", buildRunName, condition)
return condition.Reason
}, time.Duration(90*time.Second), 10*time.Second).
Should(Equal("Failed"), "BuildRun should end up in timeout")
}

0 comments on commit eab8062

Please sign in to comment.