github.com/sleungcy/cli@v7.1.0+incompatible/actor/v7pushaction/handle_app_name_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("HandleAppNameOverride", func() { 14 var ( 15 originalManifest manifestparser.Manifest 16 transformedManifest manifestparser.Manifest 17 overrides FlagOverrides 18 executeErr error 19 ) 20 21 BeforeEach(func() { 22 originalManifest.Applications = []manifestparser.Application{ 23 { 24 Name: "app-1", 25 }, 26 { 27 Name: "app-2", 28 }, 29 } 30 overrides = FlagOverrides{} 31 }) 32 33 JustBeforeEach(func() { 34 transformedManifest, executeErr = HandleAppNameOverride(originalManifest, overrides) 35 }) 36 37 When("app name is not given as arg", func() { 38 It("does not change the manifest", func() { 39 Expect(executeErr).ToNot(HaveOccurred()) 40 Expect(transformedManifest.Applications).To(ConsistOf( 41 manifestparser.Application{ 42 Name: "app-1", 43 }, 44 manifestparser.Application{ 45 Name: "app-2", 46 }, 47 )) 48 }) 49 }) 50 51 When("a valid app name is set as a manifest override", func() { 52 BeforeEach(func() { 53 overrides.AppName = "app-2" 54 }) 55 56 It("removes non-specified apps from manifest", func() { 57 Expect(executeErr).ToNot(HaveOccurred()) 58 numApps := len(transformedManifest.Applications) 59 Expect(numApps).To(Equal(1)) 60 Expect(transformedManifest.Applications).To(ConsistOf( 61 manifestparser.Application{ 62 Name: "app-2", 63 }, 64 )) 65 }) 66 }) 67 68 When("there is only one app, with no name, and a name is given as a manifest override", func() { 69 BeforeEach(func() { 70 originalManifest.Applications = []manifestparser.Application{ 71 {}, 72 } 73 74 overrides.AppName = "app-2" 75 }) 76 77 It("gives the app a name in the manifest", func() { 78 Expect(executeErr).ToNot(HaveOccurred()) 79 numApps := len(transformedManifest.Applications) 80 Expect(numApps).To(Equal(1)) 81 Expect(transformedManifest.Applications).To(ConsistOf( 82 manifestparser.Application{ 83 Name: "app-2", 84 }, 85 )) 86 }) 87 }) 88 89 When("there are multiple apps and one does not have a name", func() { 90 BeforeEach(func() { 91 originalManifest.Applications = []manifestparser.Application{ 92 { 93 Name: "app-1", 94 }, 95 { 96 Name: "", 97 }, 98 } 99 }) 100 101 It("returns an error", func() { 102 Expect(executeErr).To(MatchError("Found an application with no name specified.")) 103 }) 104 }) 105 106 When("an invalid app name is set as a manifest override", func() { 107 BeforeEach(func() { 108 overrides.AppName = "unknown-app" 109 }) 110 111 It("returns an error", func() { 112 Expect(executeErr).To(MatchError(manifestparser.AppNotInManifestError{Name: "unknown-app"})) 113 }) 114 }) 115 116 When("the manifest has no name and no appName arg is given", func() { 117 BeforeEach(func() { 118 originalManifest.Applications = []manifestparser.Application{ 119 {}, 120 } 121 }) 122 123 It("returns a AppNameOrManifestRequiredError", func() { 124 Expect(executeErr).To(MatchError(translatableerror.AppNameOrManifestRequiredError{})) 125 }) 126 }) 127 })