github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/unmap_route_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     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("unmap-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("unmap-route", "ROUTES", "Remove a route from an app"))
    19  		})
    20  
    21  		It("Displays command usage to output", func() {
    22  			session := helpers.CF("unmap-route", "--help")
    23  			Eventually(session).Should(Say(`NAME:`))
    24  			Eventually(session).Should(Say(`unmap-route - Remove a route from an app\n`))
    25  			Eventually(session).Should(Say(`\n`))
    26  
    27  			Eventually(session).Should(Say(`USAGE:`))
    28  			Eventually(session).Should(Say(`\s+cf unmap-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 unmap-route my-app example.com                              # example.com`))
    33  			Eventually(session).Should(Say(`cf unmap-route my-app example.com --hostname myhost            # myhost.example.com`))
    34  			Eventually(session).Should(Say(`cf unmap-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 used to identify the HTTP route`))
    39  			Eventually(session).Should(Say(`--path\s+Path used to identify the HTTP route`))
    40  			Eventually(session).Should(Say(`\n`))
    41  
    42  			Eventually(session).Should(Say(`SEE ALSO:`))
    43  			Eventually(session).Should(Say(`delete-route, map-route, routes`))
    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  			hostName   string
    60  			path       string
    61  			domainName string
    62  			userName   string
    63  			appName    string
    64  			route      helpers.Route
    65  		)
    66  
    67  		BeforeEach(func() {
    68  			orgName = helpers.NewOrgName()
    69  			spaceName = helpers.NewSpaceName()
    70  			appName = helpers.NewAppName()
    71  			hostName = helpers.NewHostName()
    72  			path = helpers.NewPath()
    73  			helpers.SetupCF(orgName, spaceName)
    74  			userName, _ = helpers.GetCredentials()
    75  			domainName = helpers.DefaultSharedDomain()
    76  			route = helpers.NewRoute(spaceName, domainName, hostName, path)
    77  			route.V7Create()
    78  
    79  			helpers.WithHelloWorldApp(func(dir string) {
    80  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "push", appName)
    81  				Eventually(session).Should(Exit(0))
    82  			})
    83  		})
    84  
    85  		AfterEach(func() {
    86  			route.Delete()
    87  		})
    88  
    89  		When("the route exists and is mapped to the app", func() {
    90  			BeforeEach(func() {
    91  				session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
    92  				Eventually(session).Should(Exit(0))
    93  			})
    94  
    95  			It("unmaps the route from the app", func() {
    96  				session := helpers.CF("unmap-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
    97  
    98  				Eventually(session).Should(Say(`Removing route %s.%s%s from app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
    99  				Eventually(session).Should(Say(`OK`))
   100  				Eventually(session).Should(Exit(0))
   101  			})
   102  		})
   103  
   104  		When("the route exists but is not mapped to the app", func() {
   105  			It("prints a message and exits with status 0", func() {
   106  				session := helpers.CF("unmap-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
   107  
   108  				Eventually(session).Should(Say("Route to be unmapped is not currently mapped to the application."))
   109  				Eventually(session).Should(Say(`OK`))
   110  				Eventually(session).Should(Exit(0))
   111  			})
   112  		})
   113  
   114  		When("the route doesnt exist", func() {
   115  			It("fails with a helpful message", func() {
   116  				session := helpers.CF("unmap-route", appName, domainName, "--hostname", "test", "--path", "does-not-exist")
   117  
   118  				Eventually(session.Err).Should(Say(`Route with host 'test', domain '%s', and path '/does-not-exist' not found.`, domainName))
   119  				Eventually(session).Should(Say(`FAILED`))
   120  				Eventually(session).Should(Exit(1))
   121  			})
   122  		})
   123  	})
   124  })