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

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