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

     1  package v7pushaction_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command/translatableerror"
     5  	"code.cloudfoundry.org/cli/types"
     6  	"code.cloudfoundry.org/cli/util/manifestparser"
     7  
     8  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("HandleStartCommandOverride", func() {
    15  	var (
    16  		originalManifest    manifestparser.Manifest
    17  		transformedManifest manifestparser.Manifest
    18  		overrides           FlagOverrides
    19  		executeErr          error
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		originalManifest = manifestparser.Manifest{}
    24  		overrides = FlagOverrides{}
    25  	})
    26  
    27  	JustBeforeEach(func() {
    28  		transformedManifest, executeErr = HandleStartCommandOverride(originalManifest, overrides)
    29  	})
    30  
    31  	When("manifest web process does not specify start command", func() {
    32  		BeforeEach(func() {
    33  			originalManifest.Applications = []manifestparser.Application{
    34  				{
    35  					Processes: []manifestparser.Process{
    36  						{Type: "web"},
    37  					},
    38  				},
    39  			}
    40  		})
    41  
    42  		When("start command is not set on the flag overrides", func() {
    43  			It("does not change the manifest", func() {
    44  				Expect(executeErr).ToNot(HaveOccurred())
    45  				Expect(transformedManifest.Applications).To(ConsistOf(
    46  					manifestparser.Application{
    47  						Processes: []manifestparser.Process{
    48  							{Type: "web"},
    49  						},
    50  					},
    51  				))
    52  			})
    53  		})
    54  
    55  		When("start command set on the flag overrides", func() {
    56  			BeforeEach(func() {
    57  				overrides.StartCommand = types.FilteredString{Value: "./start.sh", IsSet: true}
    58  			})
    59  
    60  			It("changes the start command of the web process in the manifest", func() {
    61  				Expect(executeErr).ToNot(HaveOccurred())
    62  				Expect(transformedManifest.Applications).To(ConsistOf(
    63  					manifestparser.Application{
    64  						Processes: []manifestparser.Process{
    65  							{Type: "web", RemainingManifestFields: map[string]interface{}{"command": "./start.sh"}},
    66  						},
    67  					},
    68  				))
    69  			})
    70  		})
    71  	})
    72  
    73  	When("start command flag is set, and manifest app has non-web processes", func() {
    74  		BeforeEach(func() {
    75  			overrides.StartCommand = types.FilteredString{Value: "./start.sh", IsSet: true}
    76  
    77  			originalManifest.Applications = []manifestparser.Application{
    78  				{
    79  					Processes: []manifestparser.Process{
    80  						{Type: "worker"},
    81  					},
    82  				},
    83  			}
    84  		})
    85  
    86  		It("changes the start command in the app level only", func() {
    87  			Expect(executeErr).ToNot(HaveOccurred())
    88  			Expect(transformedManifest.Applications).To(ConsistOf(
    89  				manifestparser.Application{
    90  					RemainingManifestFields: map[string]interface{}{"command": "./start.sh"},
    91  					Processes: []manifestparser.Process{
    92  						{Type: "worker"},
    93  					},
    94  				},
    95  			))
    96  		})
    97  	})
    98  
    99  	When("start command flag is set, and manifest app has web and non-web processes", func() {
   100  		BeforeEach(func() {
   101  			overrides.StartCommand = types.FilteredString{Value: "./start.sh", IsSet: true}
   102  
   103  			originalManifest.Applications = []manifestparser.Application{
   104  				{
   105  					Processes: []manifestparser.Process{
   106  						{Type: "worker"},
   107  						{Type: "web"},
   108  					},
   109  				},
   110  			}
   111  		})
   112  
   113  		It("changes the start command of the web process in the manifest", func() {
   114  			Expect(executeErr).ToNot(HaveOccurred())
   115  			Expect(transformedManifest.Applications).To(ConsistOf(
   116  				manifestparser.Application{
   117  					Processes: []manifestparser.Process{
   118  						{Type: "worker"},
   119  						{Type: "web", RemainingManifestFields: map[string]interface{}{"command": "./start.sh"}},
   120  					},
   121  				},
   122  			))
   123  		})
   124  	})
   125  
   126  	When("start command flag is set and there are multiple apps in the manifest", func() {
   127  		BeforeEach(func() {
   128  			overrides.StartCommand = types.FilteredString{Value: "./start.sh", IsSet: true}
   129  
   130  			originalManifest.Applications = []manifestparser.Application{
   131  				{},
   132  				{},
   133  			}
   134  		})
   135  
   136  		It("returns an error", func() {
   137  			Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{}))
   138  		})
   139  	})
   140  
   141  	When("start command set on the flag overrides but is default", func() {
   142  		BeforeEach(func() {
   143  			overrides.StartCommand = types.FilteredString{Value: "", IsSet: true}
   144  			originalManifest.Applications = []manifestparser.Application{
   145  				{},
   146  			}
   147  		})
   148  
   149  		It("changes the start command of the web process in the manifest", func() {
   150  			Expect(executeErr).ToNot(HaveOccurred())
   151  			Expect(transformedManifest.Applications[0].RemainingManifestFields["command"]).To(BeNil())
   152  		})
   153  	})
   154  })