github.com/arunkumar7540/cli@v6.45.0+incompatible/actor/v7pushaction/create_push_plans_test.go (about) 1 package v7pushaction_test 2 3 import ( 4 "fmt" 5 6 . "code.cloudfoundry.org/cli/actor/v7pushaction" 7 "code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes" 8 "code.cloudfoundry.org/cli/util/manifestparser" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("CreatePushPlans", func() { 14 var ( 15 pushActor *Actor 16 17 appNameArg string 18 spaceGUID string 19 orgGUID string 20 fakeManifestParser *v7pushactionfakes.FakeManifestParser 21 flagOverrides FlagOverrides 22 23 pushPlans []PushPlan 24 executeErr error 25 26 testUpdatePlanCount int 27 ) 28 29 testUpdatePlan := func(pushState PushPlan, overrides FlagOverrides, manifestApp manifestparser.Application) (PushPlan, error) { 30 testUpdatePlanCount += 1 31 pushState.Application.Name = manifestApp.Name 32 return pushState, nil 33 } 34 35 BeforeEach(func() { 36 pushActor, _, _, _ = getTestPushActor() 37 pushActor.PreparePushPlanSequence = []UpdatePushPlanFunc{testUpdatePlan, testUpdatePlan} 38 39 appNameArg = "my-app" 40 orgGUID = "org" 41 spaceGUID = "space" 42 flagOverrides = FlagOverrides{} 43 fakeManifestParser = new(v7pushactionfakes.FakeManifestParser) 44 45 testUpdatePlanCount = 0 46 }) 47 48 JustBeforeEach(func() { 49 pushPlans, executeErr = pushActor.CreatePushPlans(appNameArg, spaceGUID, orgGUID, fakeManifestParser, flagOverrides) 50 }) 51 52 AssertNoExecuteErr := func() { 53 It("returns nil", func() { 54 Expect(executeErr).ToNot(HaveOccurred()) 55 }) 56 } 57 58 AssertPushPlanLength := func(length int) { 59 It(fmt.Sprintf("creates a []pushPlan with length %d", length), func() { 60 Expect(pushPlans).To(HaveLen(length)) 61 }) 62 } 63 64 Describe("Manifest", func() { 65 When("There are multiple apps", func() { 66 BeforeEach(func() { 67 fakeManifestParser.AppsReturns([]manifestparser.Application{ 68 { 69 ApplicationModel: manifestparser.ApplicationModel{ 70 Name: "my-app", 71 }, 72 FullUnmarshalledApplication: nil, 73 }, 74 { 75 ApplicationModel: manifestparser.ApplicationModel{ 76 Name: "spencers-app", 77 }, 78 FullUnmarshalledApplication: nil, 79 }, 80 }, nil) 81 82 fakeManifestParser.ContainsManifestReturns(true) 83 84 appNameArg = "" 85 }) 86 87 AssertNoExecuteErr() 88 AssertPushPlanLength(2) 89 90 It("it creates pushPlans based on the apps in the manifest", func() { 91 Expect(pushPlans[0].Application.Name).To(Equal("my-app")) 92 Expect(pushPlans[1].Application.Name).To(Equal("spencers-app")) 93 }) 94 }) 95 96 When("There is an appName specified", func() { 97 When("And that appName is NOT present in the manifest", func() { 98 BeforeEach(func() { 99 fakeManifestParser.AppsReturns(nil, manifestparser.AppNotInManifestError{Name: appNameArg}) 100 101 fakeManifestParser.ContainsManifestReturns(true) 102 103 appNameArg = "my-app" 104 }) 105 106 It("it returns an AppNotInManifestError", func() { 107 Expect(executeErr).To(MatchError(manifestparser.AppNotInManifestError{Name: appNameArg})) 108 }) 109 }) 110 When("And that appName is present in the manifest", func() { 111 BeforeEach(func() { 112 fakeManifestParser.AppsReturns([]manifestparser.Application{ 113 { 114 ApplicationModel: manifestparser.ApplicationModel{ 115 Name: "my-app", 116 }, 117 FullUnmarshalledApplication: nil, 118 }, 119 }, nil) 120 121 fakeManifestParser.ContainsManifestReturns(true) 122 123 appNameArg = "my-app" 124 flagOverrides.DockerImage = "image" 125 }) 126 127 AssertNoExecuteErr() 128 AssertPushPlanLength(1) 129 130 It("it creates pushPlans based on the named app in the manifest", func() { 131 Expect(pushPlans[0].Application.Name).To(Equal("my-app")) 132 }) 133 }) 134 }) 135 }) 136 137 Describe("Org and Space GUID", func() { 138 It("creates pushPlans with org and space GUIDs", func() { 139 Expect(pushPlans[0].SpaceGUID).To(Equal(spaceGUID)) 140 Expect(pushPlans[0].OrgGUID).To(Equal(orgGUID)) 141 }) 142 }) 143 144 Describe("update push plans", func() { 145 It("runs through all the update push plan functions", func() { 146 Expect(testUpdatePlanCount).To(Equal(2)) 147 }) 148 }) 149 })