github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/isolated/map_route_command_test.go (about) 1 package isolated 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 5 "code.cloudfoundry.org/cli/integration/helpers" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("map-route command", func() { 14 Context("help", func() { 15 It("appears in cf help -a", func() { 16 session := helpers.CF("help", "-a") 17 Eventually(session).Should(Exit(0)) 18 Expect(session).To(HaveCommandInCategoryWithDescription("map-route", "ROUTES", "Map a route to an app")) 19 }) 20 21 It("displays command usage to output", func() { 22 session := helpers.CF("map-route", "--help") 23 Eventually(session).Should(Say(`NAME:`)) 24 Eventually(session).Should(Say(`map-route - Map a route to an app\n`)) 25 Eventually(session).Should(Say(`\n`)) 26 27 Eventually(session).Should(Say(`USAGE:`)) 28 Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`)) 29 Eventually(session).Should(Say(`\n`)) 30 31 Eventually(session).Should(Say(`EXAMPLES:`)) 32 Eventually(session).Should(Say(`cf map-route my-app example.com # example.com`)) 33 Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost # myhost.example.com`)) 34 Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --path foo # myhost.example.com/foo`)) 35 Eventually(session).Should(Say(`\n`)) 36 37 Eventually(session).Should(Say(`OPTIONS:`)) 38 Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`)) 39 Eventually(session).Should(Say(`--path\s+Path for the HTTP route`)) 40 Eventually(session).Should(Say(`\n`)) 41 42 Eventually(session).Should(Say(`SEE ALSO:`)) 43 Eventually(session).Should(Say(`create-route, routes, unmap-route`)) 44 45 Eventually(session).Should(Exit(0)) 46 }) 47 }) 48 49 When("the environment is not setup correctly", func() { 50 It("fails with the appropriate errors", func() { 51 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "map-route", "app-name", "domain-name") 52 }) 53 }) 54 55 When("the environment is set up correctly", func() { 56 var ( 57 orgName string 58 spaceName string 59 domainName string 60 hostName string 61 path string 62 userName string 63 appName string 64 ) 65 66 BeforeEach(func() { 67 appName = helpers.NewAppName() 68 hostName = helpers.NewHostName() 69 path = helpers.NewPath() 70 orgName = helpers.NewOrgName() 71 spaceName = helpers.NewSpaceName() 72 helpers.SetupCF(orgName, spaceName) 73 userName, _ = helpers.GetCredentials() 74 domainName = helpers.DefaultSharedDomain() 75 76 helpers.WithHelloWorldApp(func(dir string) { 77 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "push", appName) 78 Eventually(session).Should(Exit(0)) 79 }) 80 }) 81 82 When("the route already exists", func() { 83 var ( 84 route helpers.Route 85 ) 86 87 BeforeEach(func() { 88 route = helpers.NewRoute(spaceName, domainName, hostName, path) 89 route.V7Create() 90 }) 91 92 AfterEach(func() { 93 route.Delete() 94 }) 95 When("route is already mapped to app", func() { 96 BeforeEach(func() { 97 session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path) 98 Eventually(session).Should(Exit(0)) 99 }) 100 It("exits 0 with helpful message saying that the route is already mapped to the app", func() { 101 session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path) 102 103 Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName)) 104 Eventually(session).Should(Say(`App '%s' is already mapped to route '%s.%s%s'\.`, appName, hostName, domainName, path)) 105 Eventually(session).Should(Say(`OK`)) 106 Eventually(session).Should(Exit(0)) 107 108 }) 109 }) 110 When("route is not yet mapped to the app", func() { 111 It("maps the route to an app", func() { 112 session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path) 113 114 Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName)) 115 Eventually(session).Should(Say(`OK`)) 116 Eventually(session).Should(Exit(0)) 117 }) 118 }) 119 }) 120 121 When("the route does *not* exist", func() { 122 It("creates the route and maps it to an app", func() { 123 session := helpers.CF("map-route", appName, domainName, "--hostname", hostName, "--path", path) 124 Eventually(session).Should(Say(`Creating route %s.%s%s for org %s / space %s as %s\.\.\.`, hostName, domainName, path, orgName, spaceName, userName)) 125 Eventually(session).Should(Say(`OK`)) 126 Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName)) 127 Eventually(session).Should(Say(`OK`)) 128 Eventually(session).Should(Exit(0)) 129 }) 130 }) 131 }) 132 })