github.com/sleungcy/cli@v7.1.0+incompatible/actor/v7pushaction/create_push_plans_test.go (about) 1 package v7pushaction_test 2 3 import ( 4 "errors" 5 "fmt" 6 7 "code.cloudfoundry.org/cli/actor/v7action" 8 . "code.cloudfoundry.org/cli/actor/v7pushaction" 9 "code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes" 10 "code.cloudfoundry.org/cli/resources" 11 "code.cloudfoundry.org/cli/util/manifestparser" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("CreatePushPlans", func() { 17 var ( 18 pushActor *Actor 19 fakeV7Actor *v7pushactionfakes.FakeV7Actor 20 21 manifest manifestparser.Manifest 22 spaceGUID string 23 orgGUID string 24 flagOverrides FlagOverrides 25 26 pushPlans []PushPlan 27 executeErr error 28 warnings v7action.Warnings 29 30 testUpdatePlanCount int 31 ) 32 33 testUpdatePlan := func(pushState PushPlan, overrides FlagOverrides) (PushPlan, error) { 34 testUpdatePlanCount += 1 35 return pushState, nil 36 } 37 38 BeforeEach(func() { 39 pushActor, fakeV7Actor, _ = getTestPushActor() 40 pushActor.PreparePushPlanSequence = []UpdatePushPlanFunc{testUpdatePlan, testUpdatePlan} 41 42 manifest = manifestparser.Manifest{ 43 Applications: []manifestparser.Application{ 44 {Name: "name-1", Path: "path1"}, 45 {Name: "name-2", Path: "path2", Docker: &manifestparser.Docker{Image: "image", Username: "uname"}}, 46 }, 47 } 48 orgGUID = "org" 49 spaceGUID = "space" 50 flagOverrides = FlagOverrides{ 51 DockerPassword: "passwd", 52 } 53 54 testUpdatePlanCount = 0 55 }) 56 57 JustBeforeEach(func() { 58 pushPlans, warnings, executeErr = pushActor.CreatePushPlans(spaceGUID, orgGUID, manifest, flagOverrides) 59 }) 60 61 AssertNoExecuteErr := func() { 62 It("returns nil", func() { 63 Expect(executeErr).ToNot(HaveOccurred()) 64 }) 65 } 66 67 AssertPushPlanLength := func(length int) { 68 It(fmt.Sprintf("creates a []pushPlan with length %d", length), func() { 69 Expect(pushPlans).To(HaveLen(length)) 70 }) 71 } 72 73 It("delegates to the V7actor to gets the apps", func() { 74 Expect(fakeV7Actor.GetApplicationsByNamesAndSpaceCallCount()).To(Equal(1)) 75 76 actualAppNames, actualSpaceGUID := fakeV7Actor.GetApplicationsByNamesAndSpaceArgsForCall(0) 77 Expect(actualAppNames).To(ConsistOf("name-1", "name-2")) 78 Expect(actualSpaceGUID).To(Equal(spaceGUID)) 79 }) 80 81 When("getting the apps fails", func() { 82 BeforeEach(func() { 83 fakeV7Actor.GetApplicationsByNamesAndSpaceReturns(nil, v7action.Warnings{"get-apps-warning"}, errors.New("get-apps-error")) 84 }) 85 86 It("returns errors and warnings", func() { 87 Expect(executeErr).To(MatchError("get-apps-error")) 88 Expect(warnings).To(ConsistOf("get-apps-warning")) 89 }) 90 }) 91 92 When("getting the apps succeeds", func() { 93 BeforeEach(func() { 94 fakeV7Actor.GetApplicationsByNamesAndSpaceReturns( 95 []resources.Application{ 96 {Name: "name-1", GUID: "app-guid-1"}, 97 {Name: "name-2", GUID: "app-guid-2"}, 98 }, 99 v7action.Warnings{"get-apps-warning"}, 100 nil, 101 ) 102 }) 103 It("runs through all the update push plan functions", func() { 104 Expect(testUpdatePlanCount).To(Equal(4)) 105 }) 106 107 AssertNoExecuteErr() 108 AssertPushPlanLength(2) 109 110 It("returns warnings", func() { 111 Expect(warnings).To(ConsistOf("get-apps-warning")) 112 }) 113 114 It("it creates pushPlans based on the apps in the manifest", func() { 115 Expect(pushPlans[0].Application.Name).To(Equal("name-1")) 116 Expect(pushPlans[0].Application.GUID).To(Equal("app-guid-1")) 117 Expect(pushPlans[0].SpaceGUID).To(Equal(spaceGUID)) 118 Expect(pushPlans[0].OrgGUID).To(Equal(orgGUID)) 119 Expect(pushPlans[0].DockerImageCredentials.Path).To(Equal("")) 120 Expect(pushPlans[0].DockerImageCredentials.Username).To(Equal("")) 121 Expect(pushPlans[0].DockerImageCredentials.Password).To(Equal("")) 122 Expect(pushPlans[0].BitsPath).To(Equal("path1")) 123 Expect(pushPlans[1].Application.Name).To(Equal("name-2")) 124 Expect(pushPlans[1].Application.GUID).To(Equal("app-guid-2")) 125 Expect(pushPlans[1].SpaceGUID).To(Equal(spaceGUID)) 126 Expect(pushPlans[1].OrgGUID).To(Equal(orgGUID)) 127 Expect(pushPlans[1].DockerImageCredentials.Path).To(Equal("image")) 128 Expect(pushPlans[1].DockerImageCredentials.Username).To(Equal("uname")) 129 Expect(pushPlans[1].DockerImageCredentials.Password).To(Equal("passwd")) 130 Expect(pushPlans[1].BitsPath).To(Equal("path2")) 131 }) 132 133 }) 134 })