github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/v3_create_package_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("v3-create-package command", func() { 12 var ( 13 orgName string 14 spaceName string 15 appName string 16 ) 17 18 BeforeEach(func() { 19 orgName = helpers.NewOrgName() 20 spaceName = helpers.NewSpaceName() 21 appName = helpers.PrefixedRandomName("app") 22 }) 23 24 Describe("help", func() { 25 Context("when --help flag is set", func() { 26 It("Displays command usage to output", func() { 27 session := helpers.CF("v3-create-package", "--help") 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say("v3-create-package - \\*\\*EXPERIMENTAL\\*\\* Uploads a V3 Package")) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say("cf v3-create-package APP_NAME")) 32 Eventually(session).Should(Exit(0)) 33 }) 34 }) 35 }) 36 37 Context("when the app name is not provided", func() { 38 It("tells the user that the app name is required, prints help text, and exits 1", func() { 39 session := helpers.CF("v3-create-package") 40 41 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 42 Eventually(session.Out).Should(Say("NAME:")) 43 Eventually(session).Should(Exit(1)) 44 }) 45 }) 46 47 Context("when the environment is not setup correctly", func() { 48 Context("when no API endpoint is set", func() { 49 BeforeEach(func() { 50 helpers.UnsetAPI() 51 }) 52 53 It("fails with no API endpoint set message", func() { 54 session := helpers.CF("v3-create-package", appName) 55 Eventually(session).Should(Say("FAILED")) 56 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 57 Eventually(session).Should(Exit(1)) 58 }) 59 }) 60 61 Context("when not logged in", func() { 62 BeforeEach(func() { 63 helpers.LogoutCF() 64 }) 65 66 It("fails with not logged in message", func() { 67 session := helpers.CF("v3-create-package", appName) 68 Eventually(session).Should(Say("FAILED")) 69 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 70 Eventually(session).Should(Exit(1)) 71 }) 72 }) 73 74 Context("when there is no org set", func() { 75 BeforeEach(func() { 76 helpers.LogoutCF() 77 helpers.LoginCF() 78 }) 79 80 It("fails with no targeted org error message", func() { 81 session := helpers.CF("v3-create-package", appName) 82 Eventually(session.Out).Should(Say("FAILED")) 83 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 84 Eventually(session).Should(Exit(1)) 85 }) 86 }) 87 88 Context("when there is no space set", func() { 89 BeforeEach(func() { 90 helpers.LogoutCF() 91 helpers.LoginCF() 92 helpers.TargetOrg(ReadOnlyOrg) 93 }) 94 95 It("fails with no targeted space error message", func() { 96 session := helpers.CF("v3-create-package", appName) 97 Eventually(session.Out).Should(Say("FAILED")) 98 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 99 Eventually(session).Should(Exit(1)) 100 }) 101 }) 102 }) 103 104 Context("when the environment is set up correctly", func() { 105 BeforeEach(func() { 106 setupCF(orgName, spaceName) 107 }) 108 109 Context("when the app does not exist", func() { 110 It("returns a not found error", func() { 111 session := helpers.CF("v3-create-package", appName) 112 userName, _ := helpers.GetCredentials() 113 Eventually(session).Should(Say("Uploading V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 114 Eventually(session.Err).Should(Say("App %s not found", appName)) 115 Eventually(session).Should(Say("FAILED")) 116 Eventually(session).Should(Exit(1)) 117 }) 118 }) 119 120 Context("when the app exists", func() { 121 BeforeEach(func() { 122 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 123 }) 124 125 It("creates the package", func() { 126 session := helpers.CF("v3-create-package", appName) 127 userName, _ := helpers.GetCredentials() 128 Eventually(session).Should(Say("Uploading V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 129 Eventually(session).Should(Say("package guid: %s", helpers.GUIDRegex)) 130 Eventually(session).Should(Say("OK")) 131 Eventually(session).Should(Exit(0)) 132 }) 133 }) 134 }) 135 })