github.com/sleungcy/cli@v7.1.0+incompatible/actor/v7pushaction/handle_instances_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("HandleInstancesOverride", 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 = HandleInstancesOverride(originalManifest, overrides) 29 }) 30 31 When("manifest web process does not specify instances", func() { 32 BeforeEach(func() { 33 originalManifest.Applications = []manifestparser.Application{ 34 { 35 Processes: []manifestparser.Process{ 36 {Type: "web"}, 37 }, 38 }, 39 } 40 }) 41 42 When("instances are not set on the flag overrides", func() { 43 It("does not change the manifest", func() { 44 Expect(executeErr).ToNot(HaveOccurred()) 45 Expect(transformedManifest).To(Equal(originalManifest)) 46 }) 47 }) 48 49 When("instances are set on the flag overrides", func() { 50 BeforeEach(func() { 51 overrides.Instances = types.NullInt{IsSet: true, Value: 4} 52 }) 53 54 It("changes the instances of the web process in the manifest", func() { 55 Expect(executeErr).ToNot(HaveOccurred()) 56 Expect(transformedManifest.Applications).To(ConsistOf( 57 manifestparser.Application{ 58 Processes: []manifestparser.Process{ 59 {Type: "web", Instances: &overrides.Instances.Value}, 60 }, 61 }, 62 )) 63 }) 64 }) 65 }) 66 67 When("instances flag is set, and manifest app has non-web processes", func() { 68 BeforeEach(func() { 69 overrides.Instances = types.NullInt{IsSet: true, Value: 4} 70 71 originalManifest.Applications = []manifestparser.Application{ 72 { 73 Processes: []manifestparser.Process{ 74 {Type: "worker"}, 75 }, 76 }, 77 } 78 }) 79 80 It("changes the instances of the app in the manifest", func() { 81 Expect(executeErr).ToNot(HaveOccurred()) 82 Expect(transformedManifest.Applications).To(ConsistOf( 83 manifestparser.Application{ 84 Instances: &overrides.Instances.Value, 85 Processes: []manifestparser.Process{ 86 {Type: "worker"}, 87 }, 88 }, 89 )) 90 }) 91 }) 92 93 When("instances flag is set, and manifest app has web and non-web processes", func() { 94 var instances = 5 95 96 BeforeEach(func() { 97 overrides.Instances = types.NullInt{IsSet: true, Value: 4} 98 99 originalManifest.Applications = []manifestparser.Application{ 100 { 101 Processes: []manifestparser.Process{ 102 {Type: "worker"}, 103 {Type: "web"}, 104 }, 105 Instances: &instances, 106 }, 107 } 108 }) 109 110 It("changes the instances of the web process in the manifest", func() { 111 Expect(executeErr).ToNot(HaveOccurred()) 112 Expect(transformedManifest.Applications).To(ConsistOf( 113 manifestparser.Application{ 114 Processes: []manifestparser.Process{ 115 {Type: "worker"}, 116 {Type: "web", Instances: &overrides.Instances.Value}, 117 }, 118 Instances: &instances, 119 }, 120 )) 121 }) 122 }) 123 124 When("instances flag is set and there are multiple apps in the manifest", func() { 125 BeforeEach(func() { 126 overrides.Instances = types.NullInt{IsSet: true, Value: 4} 127 128 originalManifest.Applications = []manifestparser.Application{ 129 {}, 130 {}, 131 } 132 }) 133 134 It("returns an error", func() { 135 Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{})) 136 }) 137 }) 138 })