Increased coverage for atc/helpers GetBuild
@@ -37,6 +37,7 @@ var _ = Describe("Helper Functions", func() {
})
Context("when passed a build id", func() {
+ Context("when no error is encountered while fetching build", func() {
Context("when build exists", func() {
BeforeEach(func() {
client.BuildReturns(expectedBuild, true, nil)
@@ -58,12 +59,26 @@ var _ = Describe("Helper Functions", func() {
It("returns an error", func() {
_, err := GetBuild(client, nil, "", expectedBuildID, "")
+ Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("build not found"))
})
})
})
+ Context("when an error is encountered while fetching build", func() {
+ BeforeEach(func() {
+ client.BuildReturns(atc.Build{}, false, errors.New("some-error"))
+ })
+
+ It("return an error", func() {
+ _, err := GetBuild(client, nil, "", expectedBuildID, "")
+ Expect(err).To(MatchError("failed to get build some-error"))
+ })
+ })
+ })
+
Context("when passed a pipeline and job name", func() {
+ Context("when no error was encountered while looking up for team job", func() {
Context("when job exists", func() {
Context("when the next build exists", func() {
BeforeEach(func() {
@@ -132,6 +147,20 @@ var _ = Describe("Helper Functions", func() {
})
})
+ Context("when an error was encountered while looking up for team job", func() {
+ BeforeEach(func() {
+ team.JobReturns(atc.Job{}, false, errors.New("some-error"))
+ })
+
+ It("should return an error", func() {
+ _, err := GetBuild(client, team, expectedJobName, "", "")
+ Expect(err).To(HaveOccurred())
+ Expect(err).To(MatchError("failed to get job some-error"))
+ })
+ })
+
+ })
+
Context("when passed pipeline, job, and build names", func() {
Context("when the build exists", func() {
BeforeEach(func() {
@@ -163,6 +192,7 @@ var _ = Describe("Helper Functions", func() {
})
Context("when nothing is passed", func() {
+ Context("when client.Builds does not return an error", func() {
var allBuilds [300]atc.Build
expectedOneOffBuild := atc.Build{
@@ -173,6 +203,7 @@ var _ = Describe("Helper Functions", func() {
APIURL: fmt.Sprintf("api/v1/builds/%s", expectedBuildID),
}
+ Context("when a build was found", func() {
BeforeEach(func() {
for i := 300 - 1; i >= 0; i-- {
allBuilds[i] = atc.Build{
@@ -215,6 +246,32 @@ var _ = Describe("Helper Functions", func() {
Expect(client.BuildsCallCount()).To(Equal(2))
})
})
+
+ Context("when no builds were found ", func() {
+ BeforeEach(func() {
+ client.BuildsReturns([]atc.Build{}, concourse.Pagination{Next: nil}, nil)
+ })
+
+ It("returns an error", func() {
+ _, err := GetBuild(client, nil, "", "", "")
+ Expect(err).To(HaveOccurred())
+ Expect(err).To(MatchError("no builds match job"))
+ })
+ })
+ })
+
+ Context("when client.Builds returns an error", func() {
+ BeforeEach(func() {
+ client.BuildsReturns(nil, concourse.Pagination{}, errors.New("some-error"))
+ })
+
+ It("should return an error", func() {
+ _, err := GetBuild(client, nil, "", "", "")
+ Expect(err).To(HaveOccurred())
+ Expect(err).To(MatchError("failed to get builds some-error"))
+ })
+ })
+ })
})
Describe("#GetLatestResourceVersions", func() {
var team *fakes.FakeTeam
