github.com/cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/resource_match_test.go (about) 1 package v7action_test 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/actor/sharedaction" 7 . "code.cloudfoundry.org/cli/actor/v7action" 8 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 11 "code.cloudfoundry.org/cli/cf/errors" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("Resource Matching", func() { 17 var ( 18 resources []sharedaction.V3Resource 19 executeErr error 20 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 21 actor *Actor 22 23 matchedResources []sharedaction.V3Resource 24 25 warnings Warnings 26 ) 27 28 BeforeEach(func() { 29 actor, fakeCloudControllerClient, _, _, _, _, _ = NewTestActor() 30 resources = []sharedaction.V3Resource{} 31 }) 32 33 JustBeforeEach(func() { 34 matchedResources, warnings, executeErr = actor.ResourceMatch(resources) 35 }) 36 37 When("The cc client succeeds", func() { 38 BeforeEach(func() { 39 for i := 1; i <= constant.MaxNumberOfResourcesForMatching+1; i++ { 40 resources = append(resources, sharedaction.V3Resource{ 41 FilePath: fmt.Sprintf("path/to/file/%d", i), 42 SizeInBytes: 1, 43 }) 44 } 45 resources = append(resources, sharedaction.V3Resource{ 46 FilePath: "empty-file", 47 SizeInBytes: 0, 48 }) 49 50 fakeCloudControllerClient.ResourceMatchReturnsOnCall(0, []ccv3.Resource{{FilePath: "path/to/file"}}, ccv3.Warnings{"this-is-a-warning"}, nil) 51 fakeCloudControllerClient.ResourceMatchReturnsOnCall(1, []ccv3.Resource{{FilePath: "path/to/other-file"}}, ccv3.Warnings{"this-is-another-warning"}, nil) 52 }) 53 54 It("passes through the list of resources with no 0 length resources", func() { 55 Expect(fakeCloudControllerClient.ResourceMatchCallCount()).To(Equal(2)) 56 57 passedResources := fakeCloudControllerClient.ResourceMatchArgsForCall(0) 58 Expect(passedResources).To(HaveLen(constant.MaxNumberOfResourcesForMatching)) 59 Expect(passedResources[0].FilePath).To(MatchRegexp("path/to/file/\\d+")) 60 61 passedResources = fakeCloudControllerClient.ResourceMatchArgsForCall(1) 62 Expect(passedResources).To(HaveLen(1)) 63 Expect(passedResources[0].FilePath).To(MatchRegexp("path/to/file/\\d+")) 64 }) 65 66 It("returns a list of sharedAction V3Resources and warnings", func() { 67 Expect(executeErr).ToNot(HaveOccurred()) 68 Expect(warnings).To(ConsistOf("this-is-a-warning", "this-is-another-warning")) 69 Expect(matchedResources).To(ConsistOf( 70 sharedaction.V3Resource{FilePath: "path/to/file"}, 71 sharedaction.V3Resource{FilePath: "path/to/other-file"})) 72 }) 73 }) 74 75 When("The cc client errors", func() { 76 BeforeEach(func() { 77 resources = []sharedaction.V3Resource{{SizeInBytes: 1}} 78 fakeCloudControllerClient.ResourceMatchReturns(nil, ccv3.Warnings{"this-is-a-warning"}, errors.New("boom")) 79 }) 80 81 It("raises the error", func() { 82 Expect(executeErr).To(MatchError("boom")) 83 Expect(warnings).To(ConsistOf(ccv3.Warnings{"this-is-a-warning"})) 84 }) 85 }) 86 })