github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/routes_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("routes 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("routes", "ROUTES", "List all routes in the current space or the current organization"))
    19  		})
    20  
    21  		It("displays the help information", func() {
    22  			session := helpers.CF("routes", "--help")
    23  			Eventually(session).Should(Say(`NAME:`))
    24  			Eventually(session).Should(Say(`routes - List all routes in the current space or the current organization\n`))
    25  			Eventually(session).Should(Say(`\n`))
    26  
    27  			Eventually(session).Should(Say(`USAGE:`))
    28  			Eventually(session).Should(Say(`cf routes \[--org-level\]\n`))
    29  			Eventually(session).Should(Say(`\n`))
    30  
    31  			Eventually(session).Should(Say(`OPTIONS:`))
    32  			Eventually(session).Should(Say(`--org-level\s+List all the routes for all spaces of current organization`))
    33  			Eventually(session).Should(Say(`\n`))
    34  
    35  			Eventually(session).Should(Say(`SEE ALSO:`))
    36  			Eventually(session).Should(Say(`check-route, create-route, domains, map-route, unmap-route`))
    37  
    38  			Eventually(session).Should(Exit(0))
    39  		})
    40  	})
    41  
    42  	When("the environment is not setup correctly", func() {
    43  		It("fails with the appropriate errors", func() {
    44  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "routes")
    45  		})
    46  	})
    47  
    48  	When("the environment is set up correctly", func() {
    49  		var (
    50  			orgName   string
    51  			spaceName string
    52  			userName  string
    53  			appName1  string
    54  			appName2  string
    55  		)
    56  
    57  		BeforeEach(func() {
    58  			orgName = helpers.NewOrgName()
    59  			spaceName = helpers.NewSpaceName()
    60  
    61  			helpers.SetupCF(orgName, spaceName)
    62  			userName, _ = helpers.GetCredentials()
    63  		})
    64  
    65  		AfterEach(func() {
    66  			helpers.QuickDeleteOrg(orgName)
    67  		})
    68  
    69  		When("routes exist", func() {
    70  			var (
    71  				domainName string
    72  				domain     helpers.Domain
    73  
    74  				otherSpaceName string
    75  			)
    76  
    77  			BeforeEach(func() {
    78  				otherSpaceName = helpers.GenerateHigherName(helpers.NewSpaceName, spaceName)
    79  
    80  				domainName = helpers.NewDomainName()
    81  
    82  				domain = helpers.NewDomain(orgName, domainName)
    83  				appName1 = helpers.NewAppName()
    84  				Eventually(helpers.CF("create-app", appName1)).Should(Exit(0))
    85  				domain.CreatePrivate()
    86  				Eventually(helpers.CF("map-route", appName1, domainName, "--hostname", "route1")).Should(Exit(0))
    87  				Eventually(helpers.CF("map-route", appName1, domainName, "--hostname", "route1a")).Should(Exit(0))
    88  				Eventually(helpers.CF("map-route", appName1, domainName, "--hostname", "route1b")).Should(Exit(0))
    89  				Eventually(helpers.CF("set-label", "route", "route1b."+domainName, "env=prod")).Should(Exit(0))
    90  
    91  				helpers.SetupCF(orgName, otherSpaceName)
    92  				appName2 = helpers.NewAppName()
    93  				Eventually(helpers.CF("create-app", appName2)).Should(Exit(0))
    94  				Eventually(helpers.CF("map-route", appName2, domainName, "--hostname", "route2", "--path", "dodo")).Should(Exit(0))
    95  
    96  				helpers.SetupCF(orgName, spaceName)
    97  			})
    98  
    99  			AfterEach(func() {
   100  				domain.Delete()
   101  				helpers.QuickDeleteSpace(otherSpaceName)
   102  			})
   103  
   104  			It("lists all the routes", func() {
   105  				session := helpers.CF("routes")
   106  				Eventually(session).Should(Exit(0))
   107  
   108  				Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   109  				Expect(session).To(Say(`space\s+host\s+domain\s+port\s+path\s+protocol\s+apps`))
   110  				Expect(session).To(Say(`%s\s+route1\s+%s\s+http\s+%s`, spaceName, domainName, appName1))
   111  				Expect(session).To(Say(`%s\s+route1a\s+%s\s+http\s+%s`, spaceName, domainName, appName1))
   112  				Expect(session).To(Say(`%s\s+route1b\s+%s\s+http\s+%s`, spaceName, domainName, appName1))
   113  				Expect(session).ToNot(Say(`%s\s+route2\s+%s\s+http\s+%s`, spaceName, domainName, appName2))
   114  			})
   115  
   116  			It("lists all the routes by label", func() {
   117  				session := helpers.CF("routes", "--labels", "env in (prod)")
   118  				Eventually(session).Should(Exit(0))
   119  				Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   120  				Expect(session).To(Say(`space\s+host\s+domain\s+port\s+path\s+protocol\s+apps`))
   121  				Expect(session).ToNot(Say(`%s\s+route1\s+%s\s+http\s+%s`, spaceName, domainName, appName1))
   122  				Expect(session).ToNot(Say(`%s\s+route1a\s+%s\s+http\s+%s`, spaceName, domainName, appName1))
   123  				Expect(session).To(Say(`%s\s+route1b\s+%s\s+http\s+%s`, spaceName, domainName, appName1))
   124  				Expect(session).ToNot(Say(`%s\s+route2\s+%s\s+http\s+%s`, spaceName, domainName, appName2))
   125  			})
   126  
   127  			When("fetching routes by org", func() {
   128  				It("lists all the routes in the org", func() {
   129  					session := helpers.CF("routes", "--org-level")
   130  					Eventually(session).Should(Say(`Getting routes for org %s as %s\.\.\.`, orgName, userName))
   131  					Eventually(session).Should(Say(`space\s+host\s+domain\s+port\s+path\s+protocol\s+apps`))
   132  					Eventually(session).Should(Say(`%s\s+route1\s+%s\s+http\s+%s`, spaceName, domainName, appName1))
   133  					Eventually(session).Should(Say(`%s\s+route2\s+%s\s+\/dodo\s+http\s+%s`, otherSpaceName, domainName, appName2))
   134  					Eventually(session).Should(Exit(0))
   135  				})
   136  			})
   137  		})
   138  
   139  		When("when shared tcp routes exist", func() {
   140  			var (
   141  				domainName  string
   142  				domain      helpers.Domain
   143  				routerGroup helpers.RouterGroup
   144  			)
   145  
   146  			BeforeEach(func() {
   147  				domainName = helpers.NewDomainName()
   148  
   149  				domain = helpers.NewDomain(orgName, domainName)
   150  
   151  				routerGroup = helpers.NewRouterGroup(
   152  					helpers.NewRouterGroupName(),
   153  					"1024-2048",
   154  				)
   155  				routerGroup.Create()
   156  				domain.CreateWithRouterGroup(routerGroup.Name)
   157  
   158  				Eventually(helpers.CF("create-route", domainName, "--port", "1028")).Should(Exit(0))
   159  			})
   160  
   161  			AfterEach(func() {
   162  				domain.DeleteShared()
   163  				routerGroup.Delete()
   164  			})
   165  
   166  			It("lists all the routes", func() {
   167  				session := helpers.CF("routes")
   168  				Eventually(session).Should(Exit(0))
   169  
   170  				Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   171  				Expect(session).To(Say(`space\s+host\s+domain\s+port\s+path\s+protocol\s+apps`))
   172  				Expect(session).To(Say(`%s\s+%s[^:]\s+%d\s+tcp`, spaceName, domainName, 1028))
   173  			})
   174  		})
   175  
   176  		When("no routes exist", func() {
   177  			It("outputs a message about no routes existing", func() {
   178  				session := helpers.CF("routes")
   179  				Eventually(session).Should(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName))
   180  				Eventually(session).Should(Say("No routes found"))
   181  				Eventually(session).Should(Exit(0))
   182  			})
   183  		})
   184  	})
   185  })