github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/actor/v7pushaction/create_docker_package_for_application_test.go (about)

     1  package v7pushaction_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/v7action"
     5  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     6  	"code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     8  	"errors"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gstruct"
    12  )
    13  
    14  var _ = Describe("CreateDockerPackageForApplication", func() {
    15  	var (
    16  		actor       *Actor
    17  		fakeV7Actor *v7pushactionfakes.FakeV7Actor
    18  
    19  		returnedPushPlan PushPlan
    20  		paramPlan        PushPlan
    21  		fakeProgressBar  *v7pushactionfakes.FakeProgressBar
    22  
    23  		warnings   Warnings
    24  		executeErr error
    25  
    26  		events []Event
    27  	)
    28  
    29  	BeforeEach(func() {
    30  		actor, _, fakeV7Actor, _ = getTestPushActor()
    31  
    32  		fakeProgressBar = new(v7pushactionfakes.FakeProgressBar)
    33  
    34  		paramPlan = PushPlan{
    35  			Application: v7action.Application{
    36  				GUID: "some-app-guid",
    37  			},
    38  			DockerImageCredentials: v7action.DockerImageCredentials{
    39  				Path:     "some-docker-image",
    40  				Password: "some-docker-password",
    41  				Username: "some-docker-username",
    42  			},
    43  			DockerImageCredentialsNeedsUpdate: true,
    44  		}
    45  	})
    46  
    47  	JustBeforeEach(func() {
    48  		events = EventFollower(func(eventStream chan<- Event) {
    49  			returnedPushPlan, warnings, executeErr = actor.CreateDockerPackageForApplication(paramPlan, eventStream, fakeProgressBar)
    50  		})
    51  	})
    52  
    53  	Describe("package upload", func() {
    54  		BeforeEach(func() {
    55  			fakeV7Actor.CreateApplicationInSpaceReturns(
    56  				v7action.Application{
    57  					GUID:          "some-app-guid",
    58  					Name:          paramPlan.Application.Name,
    59  					LifecycleType: constant.AppLifecycleTypeDocker,
    60  				},
    61  				v7action.Warnings{"some-app-warnings"},
    62  				nil)
    63  		})
    64  
    65  		When("creating the package is successful", func() {
    66  			BeforeEach(func() {
    67  				fakeV7Actor.CreateDockerPackageByApplicationReturns(
    68  					v7action.Package{GUID: "some-package-guid"},
    69  					v7action.Warnings{"some-package-warnings"},
    70  					nil)
    71  			})
    72  
    73  			It("sets the docker image", func() {
    74  				Expect(executeErr).ToNot(HaveOccurred())
    75  				Expect(warnings).To(ConsistOf("some-package-warnings"))
    76  				Expect(events).To(ConsistOf(SetDockerImage, SetDockerImageComplete))
    77  				Expect(fakeV7Actor.CreateDockerPackageByApplicationCallCount()).To(Equal(1))
    78  
    79  				appGUID, dockerCredentials := fakeV7Actor.CreateDockerPackageByApplicationArgsForCall(0)
    80  				Expect(appGUID).To(Equal("some-app-guid"))
    81  				Expect(dockerCredentials).To(MatchFields(IgnoreExtras,
    82  					Fields{
    83  						"Path":     Equal("some-docker-image"),
    84  						"Username": Equal("some-docker-username"),
    85  						"Password": Equal("some-docker-password"),
    86  					}))
    87  
    88  				Expect(fakeV7Actor.PollPackageArgsForCall(0)).To(MatchFields(IgnoreExtras,
    89  					Fields{
    90  						"GUID": Equal("some-package-guid"),
    91  					}))
    92  			})
    93  		})
    94  
    95  		When("creating the package errors", func() {
    96  			var someErr error
    97  
    98  			BeforeEach(func() {
    99  				someErr = errors.New("I AM A BANANA")
   100  				fakeV7Actor.CreateDockerPackageByApplicationReturns(v7action.Package{}, v7action.Warnings{"some-package-warnings"}, someErr)
   101  			})
   102  
   103  			It("returns errors and warnings", func() {
   104  				Expect(executeErr).To(MatchError(someErr))
   105  				Expect(events).To(ConsistOf(SetDockerImage))
   106  				Expect(warnings).To(ConsistOf("some-package-warnings"))
   107  			})
   108  		})
   109  	})
   110  
   111  	Describe("polling package", func() {
   112  		When("the the polling is successful", func() {
   113  			BeforeEach(func() {
   114  				fakeV7Actor.PollPackageReturns(v7action.Package{GUID: "some-package-guid"}, v7action.Warnings{"some-poll-package-warning"}, nil)
   115  			})
   116  
   117  			It("returns warnings", func() {
   118  				Expect(events).To(ConsistOf(SetDockerImage, SetDockerImageComplete))
   119  				Expect(warnings).To(ConsistOf("some-poll-package-warning"))
   120  			})
   121  
   122  			It("sets the package guid on push plan", func() {
   123  				Expect(returnedPushPlan.PackageGUID).To(Equal("some-package-guid"))
   124  			})
   125  		})
   126  
   127  		When("the the polling returns an error", func() {
   128  			var someErr error
   129  
   130  			BeforeEach(func() {
   131  				someErr = errors.New("I AM A BANANA")
   132  				fakeV7Actor.PollPackageReturns(v7action.Package{}, v7action.Warnings{"some-poll-package-warning"}, someErr)
   133  			})
   134  
   135  			It("returns errors and warnings", func() {
   136  				Expect(events).To(ConsistOf(SetDockerImage, SetDockerImageComplete))
   137  				Expect(executeErr).To(MatchError(someErr))
   138  			})
   139  		})
   140  	})
   141  })