code.cloudfoundry.org/cli@v7.1.0+incompatible/actor/v7pushaction/set_droplet_for_application_test.go (about)

     1  package v7pushaction_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/v7action"
     7  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     8  	"code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes"
     9  	"code.cloudfoundry.org/cli/resources"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("SetDropletForApplication", func() {
    15  	var (
    16  		actor       *Actor
    17  		fakeV7Actor *v7pushactionfakes.FakeV7Actor
    18  
    19  		paramPlan PushPlan
    20  
    21  		warnings   Warnings
    22  		executeErr error
    23  
    24  		events []Event
    25  	)
    26  
    27  	BeforeEach(func() {
    28  		actor, fakeV7Actor, _ = getTestPushActor()
    29  
    30  		paramPlan = PushPlan{
    31  			Application: resources.Application{
    32  				GUID: "some-app-guid",
    33  			},
    34  			DropletGUID: "some-droplet-guid",
    35  		}
    36  	})
    37  
    38  	JustBeforeEach(func() {
    39  		events = EventFollower(func(eventStream chan<- *PushEvent) {
    40  			_, warnings, executeErr = actor.SetDropletForApplication(paramPlan, eventStream, nil)
    41  		})
    42  	})
    43  
    44  	When("setting the droplet is successful", func() {
    45  		BeforeEach(func() {
    46  			fakeV7Actor.SetApplicationDropletReturns(v7action.Warnings{"some-set-droplet-warning"}, nil)
    47  		})
    48  
    49  		It("returns a SetDropletComplete event and warnings", func() {
    50  			Expect(executeErr).ToNot(HaveOccurred())
    51  			Expect(warnings).To(ConsistOf("some-set-droplet-warning"))
    52  			Expect(events).To(ConsistOf(SettingDroplet, SetDropletComplete))
    53  
    54  			Expect(fakeV7Actor.SetApplicationDropletCallCount()).To(Equal(1))
    55  			appGUID, dropletGUID := fakeV7Actor.SetApplicationDropletArgsForCall(0)
    56  			Expect(appGUID).To(Equal("some-app-guid"))
    57  			Expect(dropletGUID).To(Equal("some-droplet-guid"))
    58  		})
    59  	})
    60  
    61  	When("setting the droplet errors", func() {
    62  		BeforeEach(func() {
    63  			fakeV7Actor.SetApplicationDropletReturns(v7action.Warnings{"some-set-droplet-warning"}, errors.New("the climate is arid"))
    64  		})
    65  
    66  		It("returns an error and warnings", func() {
    67  			Expect(executeErr).To(MatchError("the climate is arid"))
    68  			Expect(warnings).To(ConsistOf("some-set-droplet-warning"))
    69  			Expect(events).To(ConsistOf(SettingDroplet))
    70  		})
    71  	})
    72  })