github.com/arunkumar7540/cli@v6.45.0+incompatible/actor/v7pushaction/setup_application_for_push_plan_test.go (about)

     1  package v7pushaction_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     6  	"code.cloudfoundry.org/cli/util/manifestparser"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("SetupApplicationForPushPlan", func() {
    12  	var (
    13  		pushPlan    PushPlan
    14  		overrides   FlagOverrides
    15  		manifestApp manifestparser.Application
    16  
    17  		expectedPushPlan PushPlan
    18  		executeErr       error
    19  
    20  		appName string
    21  	)
    22  
    23  	BeforeEach(func() {
    24  		appName = "some-app-name"
    25  
    26  		pushPlan = PushPlan{}
    27  		overrides = FlagOverrides{}
    28  		manifestApp = manifestparser.Application{}
    29  		manifestApp.Name = appName
    30  	})
    31  
    32  	JustBeforeEach(func() {
    33  		expectedPushPlan, executeErr = SetupApplicationForPushPlan(pushPlan, overrides, manifestApp)
    34  	})
    35  
    36  	AssertNameIsSet := func() {
    37  		It("sets the name", func() {
    38  			Expect(expectedPushPlan.Application.Name).To(Equal(appName))
    39  		})
    40  	}
    41  
    42  	AssertNoExecuteErr := func() {
    43  		It("returns nil", func() {
    44  			Expect(executeErr).ToNot(HaveOccurred())
    45  		})
    46  	}
    47  
    48  	Describe("LifecycleType", func() {
    49  		When("our overrides contain a DockerImage", func() {
    50  			BeforeEach(func() {
    51  				overrides.DockerImage = "docker://yes/yes"
    52  			})
    53  
    54  			It("creates a pushPlan with an app with LifecycleType docker", func() {
    55  				Expect(expectedPushPlan.Application.LifecycleType).
    56  					To(Equal(constant.AppLifecycleTypeDocker))
    57  			})
    58  
    59  			AssertNoExecuteErr()
    60  			AssertNameIsSet()
    61  		})
    62  
    63  		When("our overrides do not contain a DockerImage", func() {
    64  			When("The app manifest contains a Docker image", func() {
    65  				BeforeEach(func() {
    66  					manifestApp.Docker = new(manifestparser.Docker)
    67  					manifestApp.Docker.Image = "docker-image"
    68  				})
    69  				It("creates a pushPlan with an app with LifecycleType docker", func() {
    70  					Expect(expectedPushPlan.Application.LifecycleType).
    71  						To(Equal(constant.AppLifecycleTypeDocker))
    72  				})
    73  
    74  				AssertNoExecuteErr()
    75  				AssertNameIsSet()
    76  			})
    77  
    78  			When("The app manifest does not contain a Docker image", func() {
    79  				It("Creates a pushPlan with an app without LifecycleType Docker", func() {
    80  					Expect(expectedPushPlan.Application.LifecycleType).
    81  						ToNot(Equal(constant.AppLifecycleTypeDocker))
    82  				})
    83  
    84  				AssertNoExecuteErr()
    85  				AssertNameIsSet()
    86  			})
    87  		})
    88  	})
    89  
    90  	Describe("Buildpacks", func() {
    91  		When("our overrides contain one or more buildpacks", func() {
    92  			BeforeEach(func() {
    93  				overrides.Buildpacks = []string{"buildpack-1", "buildpack-2"}
    94  			})
    95  
    96  			It("creates a pushPlan with an app with Buildpacks set", func() {
    97  				Expect(expectedPushPlan.Application.LifecycleBuildpacks).To(Equal(
    98  					[]string{"buildpack-1", "buildpack-2"},
    99  				))
   100  			})
   101  
   102  			It("creates a pushPlan with an app with LifecycleType set to Buildpacks", func() {
   103  				Expect(expectedPushPlan.Application.LifecycleType).
   104  					To(Equal(constant.AppLifecycleTypeBuildpack))
   105  			})
   106  
   107  			It("creates a pushPlan with an app with applicationNeedsUpdate set", func() {
   108  				Expect(expectedPushPlan.ApplicationNeedsUpdate).To(BeTrue())
   109  			})
   110  
   111  			AssertNoExecuteErr()
   112  			AssertNameIsSet()
   113  		})
   114  
   115  		When("our overrides do not contain buildpacks", func() {
   116  			It("creates a pushPlan with an app without Buildpacks set", func() {
   117  				Expect(expectedPushPlan.Application.LifecycleBuildpacks).
   118  					To(HaveLen(0))
   119  			})
   120  
   121  			It("creates a pushPlan with an app without applicationNeedsUpdate", func() {
   122  				Expect(expectedPushPlan.ApplicationNeedsUpdate).To(BeFalse())
   123  			})
   124  
   125  			AssertNoExecuteErr()
   126  			AssertNameIsSet()
   127  		})
   128  	})
   129  
   130  	Describe("Stacks", func() {
   131  		When("our overrides contain a stack", func() {
   132  			BeforeEach(func() {
   133  				overrides.Stack = "stack"
   134  			})
   135  
   136  			It("creates a pushPlan with an application with StackName matching the override", func() {
   137  				Expect(expectedPushPlan.Application.StackName).To(Equal("stack"))
   138  			})
   139  
   140  			It("creates a pushPlan with an app with LifecycleType set to Buildpacks", func() {
   141  				Expect(expectedPushPlan.Application.LifecycleType).
   142  					To(Equal(constant.AppLifecycleTypeBuildpack))
   143  			})
   144  
   145  			It("creates a pushPlan with an app with ApplicationNeedsUpdate set", func() {
   146  				Expect(expectedPushPlan.ApplicationNeedsUpdate).To(BeTrue())
   147  			})
   148  
   149  			AssertNoExecuteErr()
   150  			AssertNameIsSet()
   151  		})
   152  
   153  		When("our overrides do not contain a stack", func() {
   154  			It("creates a pushPlan with an app without StackName set", func() {
   155  				Expect(expectedPushPlan.Application.StackName).To(BeEmpty())
   156  			})
   157  
   158  			It("creates a pushPlan with an app without Buildpacks set", func() {
   159  				Expect(expectedPushPlan.Application.LifecycleBuildpacks).
   160  					To(HaveLen(0))
   161  			})
   162  
   163  			It("creates a pushPlan with an app without applicationNeedsUpdate", func() {
   164  				Expect(expectedPushPlan.ApplicationNeedsUpdate).To(BeFalse())
   165  			})
   166  		})
   167  	})
   168  })