github.com/arunkumar7540/cli@v6.45.0+incompatible/actor/v7pushaction/resource_match_test.go (about) 1 package v7pushaction_test 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v7action" 6 . "code.cloudfoundry.org/cli/actor/v7pushaction" 7 "code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 9 "errors" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("MatchResources", func() { 15 var ( 16 actor *Actor 17 fakeV7Actor *v7pushactionfakes.FakeV7Actor 18 19 resources []sharedaction.V3Resource 20 executeErr error 21 22 matched []sharedaction.V3Resource 23 unmatched []sharedaction.V3Resource 24 warnings Warnings 25 ) 26 27 BeforeEach(func() { 28 actor, _, fakeV7Actor, _ = getTestPushActor() 29 }) 30 31 JustBeforeEach(func() { 32 matched, unmatched, warnings, executeErr = actor.MatchResources(resources) 33 }) 34 35 When("all the resources are unmatched", func() { 36 BeforeEach(func() { 37 resources = []sharedaction.V3Resource{ 38 {Checksum: ccv3.Checksum{Value: "file-1"}}, 39 {Checksum: ccv3.Checksum{Value: "file-2"}}, 40 {Checksum: ccv3.Checksum{Value: "file-3"}}, 41 } 42 43 fakeV7Actor.ResourceMatchReturns( 44 []sharedaction.V3Resource{}, 45 v7action.Warnings{"all-unmatched-warning"}, 46 nil, 47 ) 48 }) 49 50 It("returns an empty slice of matches and a complete slice of unmatches (in the order provided)", func() { 51 Expect(executeErr).To(BeNil()) 52 Expect(matched).To(BeEmpty()) 53 Expect(unmatched).To(Equal(resources)) 54 Expect(warnings).To(Equal(Warnings{"all-unmatched-warning"})) 55 }) 56 }) 57 58 When("all the resources are matched", func() { 59 BeforeEach(func() { 60 resources = []sharedaction.V3Resource{ 61 {Checksum: ccv3.Checksum{Value: "file-1"}}, 62 {Checksum: ccv3.Checksum{Value: "file-2"}}, 63 {Checksum: ccv3.Checksum{Value: "file-3"}}, 64 } 65 66 fakeV7Actor.ResourceMatchReturns( 67 resources, 68 v7action.Warnings{"all-unmatched-warning"}, 69 nil, 70 ) 71 }) 72 73 It("returns a complete slice of matches and an empty slice of unmatches (in the order provided)", func() { 74 Expect(executeErr).To(BeNil()) 75 Expect(matched).To(Equal(resources)) 76 Expect(unmatched).To(BeEmpty()) 77 Expect(warnings).To(Equal(Warnings{"all-unmatched-warning"})) 78 }) 79 }) 80 81 When("some of the resources are matched", func() { 82 var expectedMatches []sharedaction.V3Resource 83 var expectedUnmatches []sharedaction.V3Resource 84 85 BeforeEach(func() { 86 resources = []sharedaction.V3Resource{ 87 {Checksum: ccv3.Checksum{Value: "file-1"}}, 88 {Checksum: ccv3.Checksum{Value: "file-2"}}, 89 {Checksum: ccv3.Checksum{Value: "file-3"}}, 90 } 91 92 expectedMatches = []sharedaction.V3Resource{ 93 {Checksum: ccv3.Checksum{Value: "file-1"}}, 94 {Checksum: ccv3.Checksum{Value: "file-3"}}, 95 } 96 97 expectedUnmatches = []sharedaction.V3Resource{ 98 {Checksum: ccv3.Checksum{Value: "file-2"}}, 99 } 100 101 fakeV7Actor.ResourceMatchReturns( 102 expectedMatches, 103 v7action.Warnings{"all-unmatched-warning"}, 104 nil, 105 ) 106 }) 107 108 It("returns a slice of matches and a slice of unmatches (in the order provided)", func() { 109 Expect(executeErr).To(BeNil()) 110 Expect(matched).To(Equal(expectedMatches)) 111 Expect(unmatched).To(Equal(expectedUnmatches)) 112 Expect(warnings).To(Equal(Warnings{"all-unmatched-warning"})) 113 }) 114 }) 115 116 When("v7actor.ResourceMatch returns an error", func() { 117 BeforeEach(func() { 118 fakeV7Actor.ResourceMatchReturns( 119 nil, 120 v7action.Warnings{ 121 "error-response-warning-1", 122 "error-response-warning-2", 123 }, 124 errors.New("error-response-text"), 125 ) 126 }) 127 128 It("returns the same error", func() { 129 Expect(executeErr).To(MatchError("error-response-text")) 130 Expect(warnings).To(ConsistOf( 131 "error-response-warning-1", 132 "error-response-warning-2", 133 )) 134 }) 135 }) 136 })