github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/unshare_route_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     7  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("unshare route command", func() {
    16  	Context("Help", func() {
    17  		It("appears in cf help -a", func() {
    18  			session := helpers.CF("help", "-a")
    19  
    20  			fmt.Println(session)
    21  
    22  			Eventually(session).Should(Exit(0))
    23  			Expect(session).To(HaveCommandInCategoryWithDescription("unshare-route", "ROUTES", "Unshare an existing route from a space"))
    24  		})
    25  
    26  		It("displays the help information", func() {
    27  			session := helpers.CF("unshare-route", "--help")
    28  			Eventually(session).Should(Say(`NAME:`))
    29  			Eventually(session).Should(Say("unshare-route - Unshare an existing route from a space"))
    30  			Eventually(session).Should(Say(`\n`))
    31  
    32  			Eventually(session).Should(Say(`USAGE:`))
    33  			Eventually(session).Should(Say(`Unshare an existing route from a space:`))
    34  			Eventually(session).Should(Say(`cf unshare-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] -s OTHER_SPACE \[-o OTHER_ORG\]`))
    35  			Eventually(session).Should(Say(`\n`))
    36  
    37  			Eventually(session).Should(Say(`EXAMPLES:`))
    38  			Eventually(session).Should(Say(`cf unshare-route example.com --hostname myHost --path foo -s TargetSpace -o TargetOrg        # myhost.example.com/foo`))
    39  			Eventually(session).Should(Say(`cf unshare-route example.com --hostname myHost -s TargetSpace                                # myhost.example.com`))
    40  			Eventually(session).Should(Say(`cf unshare-route example.com --hostname myHost -s TargetSpace -o TargetOrg                   # myhost.example.com`))
    41  			Eventually(session).Should(Say(`\n`))
    42  
    43  			Eventually(session).Should(Say(`OPTIONS:`))
    44  			Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
    45  			Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
    46  			Eventually(session).Should(Say(`-o\s+The org of the destination space \(Default: targeted org\)`))
    47  			Eventually(session).Should(Say(`-s\s+The space to be unshared \(Default: targeted space\)`))
    48  			Eventually(session).Should(Say(`\n`))
    49  
    50  			Eventually(session).Should(Say(`SEE ALSO:`))
    51  			Eventually(session).Should(Say(`share-route, delete-route, map-route, routes, unmap-route`))
    52  
    53  			Eventually(session).Should(Exit(0))
    54  		})
    55  	})
    56  
    57  	When("the environment is not setup correctly", func() {
    58  		It("fails with the appropriate errors", func() {
    59  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "unshare-route", "some-domain", "-s SOME_SPACE")
    60  		})
    61  	})
    62  
    63  	When("the environment is set up correctly", func() {
    64  		var (
    65  			userName  string
    66  			orgName   string
    67  			spaceName string
    68  		)
    69  
    70  		BeforeEach(func() {
    71  			helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3)
    72  			orgName = helpers.NewOrgName()
    73  			spaceName = helpers.NewSpaceName()
    74  
    75  			helpers.SetupCF(orgName, spaceName)
    76  			userName, _ = helpers.GetCredentials()
    77  		})
    78  
    79  		AfterEach(func() {
    80  			helpers.QuickDeleteOrg(orgName)
    81  		})
    82  
    83  		When("the domain extists", func() {
    84  			var (
    85  				domainName      string
    86  				targetSpaceName string
    87  			)
    88  
    89  			BeforeEach(func() {
    90  				domainName = helpers.NewDomainName()
    91  			})
    92  
    93  			When("the route exists", func() {
    94  				var (
    95  					domain   helpers.Domain
    96  					hostname string
    97  				)
    98  				When("the target space is shared in the targedted space", func() {
    99  					BeforeEach(func() {
   100  						domain = helpers.NewDomain(orgName, domainName)
   101  						hostname = "panera-bread"
   102  						targetSpaceName = helpers.NewSpaceName()
   103  						helpers.CreateSpace(targetSpaceName)
   104  						domain.Create()
   105  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   106  						Eventually(helpers.CF("share-route", domain.Name, "--hostname", hostname, "-s", targetSpaceName)).Should(Exit(0))
   107  					})
   108  
   109  					AfterEach(func() {
   110  						domain.Delete()
   111  					})
   112  
   113  					It("unshares the route to the destination space", func() {
   114  						session := helpers.CF("unshare-route", domainName, "--hostname", hostname, "-s", targetSpaceName)
   115  						Eventually(session).Should(Say(`Unsharing route %s.%s from space %s as %s`, hostname, domainName, targetSpaceName, userName))
   116  						Eventually(session).Should(Say(`OK`))
   117  						Eventually(session).Should(Exit(0))
   118  					})
   119  				})
   120  
   121  				When("the target organization does not exist", func() {
   122  					var targetOrgName string
   123  					BeforeEach(func() {
   124  						domain = helpers.NewDomain(orgName, domainName)
   125  						hostname = "panera-bread"
   126  						targetSpaceName = helpers.NewSpaceName()
   127  						targetOrgName = helpers.NewOrgName()
   128  						domain.Create()
   129  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   130  					})
   131  
   132  					It("exists with 1 and an error message", func() {
   133  						session := helpers.CF("unshare-route", domainName, "--hostname", hostname, "-o", targetOrgName, "-s", targetSpaceName)
   134  						Eventually(session).Should(Say("Can not unshare route:"))
   135  						Eventually(session).Should(Say(`FAILED`))
   136  						Eventually(session).Should(Exit(1))
   137  					})
   138  				})
   139  
   140  				When("the target space exists in another existing org", func() {
   141  					var targetOrgName string
   142  					BeforeEach(func() {
   143  						domain = helpers.NewDomain(orgName, domainName)
   144  						hostname = "menchies-icecream"
   145  						targetOrgName = helpers.NewOrgName()
   146  						targetSpaceName = helpers.NewSpaceName()
   147  						helpers.CreateOrgAndSpace(targetOrgName, targetSpaceName)
   148  						helpers.SetupCF(orgName, spaceName)
   149  						domain.Create()
   150  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   151  					})
   152  
   153  					AfterEach(func() {
   154  						domain.Delete()
   155  					})
   156  
   157  					It("unshared the route from the intended space", func() {
   158  						session := helpers.CF("unshare-route", domainName, "--hostname", hostname, "-o", targetOrgName, "-s", targetSpaceName)
   159  						Eventually(session).Should(Say(`Unsharing route %s.%s from space %s as %s`, hostname, domainName, targetSpaceName, userName))
   160  						Eventually(session).Should(Say(`OK`))
   161  						Eventually(session).Should(Exit(0))
   162  					})
   163  				})
   164  
   165  				When("the space does not exist", func() {
   166  					var destinationSpaceName string
   167  					BeforeEach(func() {
   168  						domain = helpers.NewDomain(orgName, domainName)
   169  						hostname = "menchies-icecream"
   170  						destinationSpaceName = "doesNotExistSpace"
   171  						domain.Create()
   172  						Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname)).Should(Exit(0))
   173  					})
   174  
   175  					It("exists with 1 with an error", func() {
   176  						session := helpers.CF("unshare-route", domainName, "--hostname", hostname, "-s", destinationSpaceName)
   177  						Eventually(session).Should(Say("Can not unshare route:"))
   178  						Eventually(session).Should(Say(`FAILED`))
   179  						Eventually(session).Should(Exit(1))
   180  					})
   181  				})
   182  			})
   183  
   184  			When("the route does not exist", func() {
   185  				var (
   186  					domain   helpers.Domain
   187  					hostname string
   188  				)
   189  
   190  				When("the target space exists", func() {
   191  					BeforeEach(func() {
   192  						domain = helpers.NewDomain(orgName, domainName)
   193  						hostname = "panera-bread"
   194  						targetSpaceName = helpers.NewSpaceName()
   195  						helpers.CreateSpace(targetSpaceName)
   196  						domain.Create()
   197  					})
   198  
   199  					It("exits with 1 with an error message", func() {
   200  						session := helpers.CF("unshare-route", domainName, "--hostname", hostname, "-s", targetSpaceName)
   201  						Eventually(session).Should(Say("Can not unshare route:"))
   202  						Eventually(session).Should(Say(`FAILED`))
   203  						Eventually(session).Should(Exit(1))
   204  					})
   205  				})
   206  			})
   207  		})
   208  	})
   209  })