github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/revisions_test.go (about) 1 package v7action_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/actor/v7action" 7 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 9 "code.cloudfoundry.org/cli/resources" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("Revisions Actions", func() { 15 16 Describe("GetRevisionsByApplicationNameAndSpace", func() { 17 var ( 18 actor *Actor 19 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 20 appName string 21 spaceGUID string 22 fetchedRevisions []resources.Revision 23 executeErr error 24 warnings Warnings 25 ) 26 27 BeforeEach(func() { 28 fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) 29 actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil) 30 appName = "some-app" 31 spaceGUID = "space-guid" 32 }) 33 34 JustBeforeEach(func() { 35 fetchedRevisions, warnings, executeErr = actor.GetRevisionsByApplicationNameAndSpace(appName, spaceGUID) 36 }) 37 38 When("finding the app fails", func() { 39 BeforeEach(func() { 40 fakeCloudControllerClient.GetApplicationsReturns(nil, ccv3.Warnings{"get-application-warning"}, errors.New("get-application-error")) 41 }) 42 43 It("returns an error", func() { 44 Expect(executeErr).To(MatchError("get-application-error")) 45 Expect(warnings).To(ConsistOf("get-application-warning")) 46 }) 47 }) 48 49 When("finding the app succeeds", func() { 50 BeforeEach(func() { 51 fakeCloudControllerClient.GetApplicationsReturns([]resources.Application{{Name: "some-app", GUID: "some-app-guid"}}, ccv3.Warnings{"get-application-warning"}, nil) 52 }) 53 54 When("getting the app revisions fails", func() { 55 BeforeEach(func() { 56 fakeCloudControllerClient.GetApplicationRevisionsReturns([]resources.Revision{}, ccv3.Warnings{"some-revisions-warnings"}, errors.New("some-revisions-error")) 57 }) 58 It("returns an error", func() { 59 Expect(executeErr).To(MatchError("some-revisions-error")) 60 Expect(warnings).To(ConsistOf("get-application-warning", "some-revisions-warnings")) 61 }) 62 }) 63 64 When("getting the app revisions succeeds", func() { 65 BeforeEach(func() { 66 fakeCloudControllerClient.GetApplicationRevisionsReturns( 67 []resources.Revision{ 68 {GUID: "3"}, 69 {GUID: "2"}, 70 {GUID: "1"}, 71 }, 72 ccv3.Warnings{"some-revisions-warnings"}, 73 nil, 74 ) 75 }) 76 77 It("makes the API call to get the app revisions and returns all warnings and revisions in descending order", func() { 78 Expect(fakeCloudControllerClient.GetApplicationsCallCount()).To(Equal(1)) 79 Expect(fakeCloudControllerClient.GetApplicationsArgsForCall(0)).To(ConsistOf( 80 ccv3.Query{Key: ccv3.NameFilter, Values: []string{appName}}, 81 ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{spaceGUID}}, 82 )) 83 84 Expect(fakeCloudControllerClient.GetApplicationRevisionsCallCount()).To(Equal(1)) 85 86 appGuidArg, queryArg := fakeCloudControllerClient.GetApplicationRevisionsArgsForCall(0) 87 Expect(appGuidArg).To(Equal("some-app-guid")) 88 Expect(queryArg).To(Equal([]ccv3.Query{{Key: ccv3.OrderBy, Values: []string{"-created_at"}}})) 89 90 Expect(fetchedRevisions).To(Equal( 91 []resources.Revision{ 92 {GUID: "3"}, 93 {GUID: "2"}, 94 {GUID: "1"}, 95 })) 96 Expect(executeErr).ToNot(HaveOccurred()) 97 Expect(warnings).To(ConsistOf("get-application-warning", "some-revisions-warnings")) 98 }) 99 }) 100 }) 101 }) 102 103 Describe("GetRevisionByApplicationAndVersion", func() { 104 var ( 105 actor *Actor 106 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 107 appGUID string 108 revisionVersion int 109 err error 110 warnings Warnings 111 revision resources.Revision 112 ) 113 114 BeforeEach(func() { 115 fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) 116 actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil) 117 appGUID = "some-app-guid" 118 revisionVersion = 1 119 }) 120 121 JustBeforeEach(func() { 122 revision, warnings, err = actor.GetRevisionByApplicationAndVersion(appGUID, revisionVersion) 123 }) 124 125 When("finding the revision succeeds", func() { 126 BeforeEach(func() { 127 fakeCloudControllerClient.GetApplicationRevisionsReturns( 128 []resources.Revision{ 129 {GUID: "revision-guid-1", Version: 1}, 130 {GUID: "revision-guid-2", Version: 2}, 131 }, 132 ccv3.Warnings{"get-revisions-warning-1"}, 133 nil, 134 ) 135 }) 136 137 It("returns the revision", func() { 138 Expect(fakeCloudControllerClient.GetApplicationRevisionsCallCount()).To(Equal(1), "GetApplicationRevisions call count") 139 Expect(fakeCloudControllerClient.GetApplicationRevisionsArgsForCall(0)).To(Equal("some-app-guid")) 140 141 Expect(revision.Version).To(Equal(1)) 142 Expect(revision.GUID).To(Equal("revision-guid-1")) 143 Expect(err).ToNot(HaveOccurred()) 144 Expect(warnings).To(ConsistOf("get-revisions-warning-1")) 145 }) 146 }) 147 }) 148 })