github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/job_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/actor/v7action"
     5  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("Job Actions", func() {
    13  	var (
    14  		actor                     *Actor
    15  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		actor, fakeCloudControllerClient, _, _, _, _, _ = NewTestActor()
    20  	})
    21  
    22  	Describe("PollUploadBuildpackJob", func() {
    23  		var (
    24  			jobURL   ccv3.JobURL
    25  			warnings Warnings
    26  			err      error
    27  		)
    28  
    29  		BeforeEach(func() {
    30  			jobURL = ccv3.JobURL("http://example.com/the-job-url")
    31  		})
    32  
    33  		JustBeforeEach(func() {
    34  			warnings, err = actor.PollUploadBuildpackJob(jobURL)
    35  		})
    36  
    37  		When("the cc client returns success", func() {
    38  			BeforeEach(func() {
    39  				fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"some-warnings"}, nil)
    40  			})
    41  
    42  			It("returns success and warnings", func() {
    43  				Expect(err).ToNot(HaveOccurred())
    44  				Expect(warnings).To(ConsistOf("some-warnings"))
    45  			})
    46  
    47  			It("calls poll job", func() {
    48  				Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
    49  				actualJobURL := fakeCloudControllerClient.PollJobArgsForCall(0)
    50  				Expect(actualJobURL).To(Equal(jobURL))
    51  			})
    52  		})
    53  
    54  		When("the cc client returns error", func() {
    55  			BeforeEach(func() {
    56  				fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"some-warnings"}, ccerror.V3JobFailedError{Detail: "some-err"})
    57  			})
    58  
    59  			It("returns the errors and warnings", func() {
    60  				warnings, err = actor.PollUploadBuildpackJob(jobURL)
    61  
    62  				Expect(err).To(MatchError(ccerror.V3JobFailedError{Detail: "some-err"}))
    63  				Expect(warnings).To(ConsistOf("some-warnings"))
    64  			})
    65  		})
    66  	})
    67  })