github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7pushaction/handle_memory_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("HandleMemoryOverride", 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 = HandleMemoryOverride(originalManifest, overrides) 28 }) 29 30 When("manifest web process does not specify memory", func() { 31 BeforeEach(func() { 32 originalManifest.Applications = []manifestparser.Application{ 33 { 34 Processes: []manifestparser.Process{ 35 {Type: "web"}, 36 }, 37 }, 38 } 39 }) 40 41 When("memory are 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("memory are set on the flag overrides", func() { 55 BeforeEach(func() { 56 overrides.Memory = "64M" 57 }) 58 59 It("changes the memory 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 {Type: "web", Memory: "64M"}, 65 }, 66 }, 67 )) 68 }) 69 }) 70 }) 71 72 When("memory flag is set, and manifest app has non-web processes", func() { 73 BeforeEach(func() { 74 overrides.Memory = "64M" 75 76 originalManifest.Applications = []manifestparser.Application{ 77 { 78 Processes: []manifestparser.Process{ 79 {Type: "worker"}, 80 }, 81 }, 82 } 83 }) 84 85 It("changes the memory of the app in the manifest", func() { 86 Expect(executeErr).ToNot(HaveOccurred()) 87 Expect(transformedManifest.Applications).To(ConsistOf( 88 manifestparser.Application{ 89 Memory: "64M", 90 Processes: []manifestparser.Process{ 91 {Type: "worker"}, 92 }, 93 }, 94 )) 95 }) 96 }) 97 98 When("memory flag is set, and manifest app has web and non-web processes", func() { 99 BeforeEach(func() { 100 overrides.Memory = "64M" 101 102 originalManifest.Applications = []manifestparser.Application{ 103 { 104 Processes: []manifestparser.Process{ 105 {Type: "worker"}, 106 {Type: "web"}, 107 }, 108 Memory: "8M", 109 }, 110 } 111 }) 112 113 It("changes the memory 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", Memory: "64M"}, 120 }, 121 Memory: "8M", 122 }, 123 )) 124 }) 125 }) 126 127 When("memory flag is set and there are multiple apps in the manifest", func() { 128 BeforeEach(func() { 129 overrides.Memory = "64M" 130 131 originalManifest.Applications = []manifestparser.Application{ 132 {}, 133 {}, 134 } 135 }) 136 137 It("returns an error", func() { 138 Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{})) 139 }) 140 }) 141 })