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