github.com/Thanhphan1147/cloudfoundry-cli@v7.1.0+incompatible/actor/v7pushaction/handle_droplet_path_override_test.go (about)

     1  package v7pushaction_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     5  	"code.cloudfoundry.org/cli/command/translatableerror"
     6  	"code.cloudfoundry.org/cli/util/manifestparser"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("HandleDropletPathOverride", func() {
    13  	var (
    14  		transformedManifest manifestparser.Manifest
    15  		executeErr          error
    16  
    17  		parsedManifest manifestparser.Manifest
    18  		flagOverrides  FlagOverrides
    19  	)
    20  
    21  	JustBeforeEach(func() {
    22  		transformedManifest, executeErr = HandleDropletPathOverride(
    23  			parsedManifest,
    24  			flagOverrides,
    25  		)
    26  	})
    27  
    28  	When("the droplet path flag override is set", func() {
    29  		BeforeEach(func() {
    30  			flagOverrides = FlagOverrides{DropletPath: "some-droplet-path.tgz"}
    31  		})
    32  
    33  		When("there are multiple apps in the manifest", func() {
    34  			BeforeEach(func() {
    35  				parsedManifest = manifestparser.Manifest{
    36  					Applications: []manifestparser.Application{
    37  						{},
    38  						{},
    39  					},
    40  				}
    41  			})
    42  
    43  			It("returns an error", func() {
    44  				Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{}))
    45  			})
    46  		})
    47  
    48  		When("there is a single app in the manifest", func() {
    49  			BeforeEach(func() {
    50  				parsedManifest = manifestparser.Manifest{
    51  					Applications: []manifestparser.Application{
    52  						{},
    53  					},
    54  				}
    55  			})
    56  
    57  			It("returns the unchanged manifest", func() {
    58  				Expect(executeErr).NotTo(HaveOccurred())
    59  				Expect(transformedManifest.Applications).To(ConsistOf(
    60  					manifestparser.Application{},
    61  				))
    62  			})
    63  		})
    64  
    65  		When("when docker is set in the manifest", func() {
    66  			BeforeEach(func() {
    67  				parsedManifest = manifestparser.Manifest{
    68  					Applications: []manifestparser.Application{
    69  						{
    70  							Name: "some-app",
    71  							Docker: &manifestparser.Docker{
    72  								Image: "nginx:latest",
    73  							},
    74  						},
    75  					},
    76  				}
    77  			})
    78  
    79  			It("returns an error", func() {
    80  				Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{
    81  					Arg:              "--droplet",
    82  					ManifestProperty: "docker",
    83  				}))
    84  			})
    85  		})
    86  
    87  		When("when buildpacks is set in the manifest", func() {
    88  			BeforeEach(func() {
    89  				parsedManifest = manifestparser.Manifest{
    90  					Applications: []manifestparser.Application{
    91  						{
    92  							Name:                    "some-app",
    93  							RemainingManifestFields: map[string]interface{}{"buildpacks": []string{"ruby_buildpack"}},
    94  						},
    95  					},
    96  				}
    97  			})
    98  
    99  			It("returns an error", func() {
   100  				Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{
   101  					Arg:              "--droplet",
   102  					ManifestProperty: "buildpacks",
   103  				}))
   104  			})
   105  		})
   106  
   107  		When("when path is set in the manifest", func() {
   108  			BeforeEach(func() {
   109  				parsedManifest = manifestparser.Manifest{
   110  					Applications: []manifestparser.Application{
   111  						{
   112  							Name: "some-app",
   113  							Path: "~",
   114  						},
   115  					},
   116  				}
   117  			})
   118  
   119  			It("returns an error", func() {
   120  				Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{
   121  					Arg:              "--droplet",
   122  					ManifestProperty: "path",
   123  				}))
   124  			})
   125  		})
   126  	})
   127  
   128  	When("the strategy flag override is not set", func() {
   129  		BeforeEach(func() {
   130  			flagOverrides = FlagOverrides{}
   131  		})
   132  
   133  		When("there are multiple apps in the manifest", func() {
   134  			BeforeEach(func() {
   135  				parsedManifest = manifestparser.Manifest{
   136  					Applications: []manifestparser.Application{
   137  						{},
   138  						{},
   139  					},
   140  				}
   141  			})
   142  
   143  			It("does not return an error", func() {
   144  				Expect(executeErr).NotTo(HaveOccurred())
   145  			})
   146  		})
   147  	})
   148  })