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

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	"code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("space command", func() {
    15  	var (
    16  		orgName   string
    17  		spaceName string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		orgName = helpers.NewOrgName()
    22  		spaceName = helpers.NewSpaceName()
    23  	})
    24  
    25  	Describe("help", func() {
    26  		When("--help flag is set", func() {
    27  			It("Displays command usage to output", func() {
    28  				session := helpers.CF("space", "--help")
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("space - Show space info"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say(`cf space SPACE \[--guid\]`))
    33  				Eventually(session).Should(Say("OPTIONS:"))
    34  				Eventually(session).Should(Say(`--guid\s+Retrieve and display the given space's guid\.  All other output for the space is suppressed\.`))
    35  				Eventually(session).Should(Say("SEE ALSO:"))
    36  				Eventually(session).Should(Say("set-space-isolation-segment, space-quota, space-users"))
    37  				Eventually(session).Should(Exit(0))
    38  			})
    39  		})
    40  	})
    41  
    42  	When("the environment is not setup correctly", func() {
    43  		It("fails with the appropriate errors", func() {
    44  			helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "space", "space-name")
    45  		})
    46  	})
    47  
    48  	When("the environment is set up correctly", func() {
    49  		BeforeEach(func() {
    50  			helpers.LoginCF()
    51  			helpers.SetupCF(orgName, spaceName)
    52  		})
    53  
    54  		AfterEach(func() {
    55  			helpers.QuickDeleteOrg(orgName)
    56  			helpers.ClearTarget()
    57  		})
    58  
    59  		When("the space does not exist", func() {
    60  			It("displays not found and exits 1", func() {
    61  				badSpaceName := fmt.Sprintf("%s-1", spaceName)
    62  				session := helpers.CF("space", badSpaceName)
    63  				userName, _ := helpers.GetCredentials()
    64  				Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, badSpaceName, orgName, userName))
    65  				Eventually(session).Should(Say("FAILED"))
    66  				Eventually(session.Err).Should(Say("Space '%s' not found.", badSpaceName))
    67  				Eventually(session).Should(Exit(1))
    68  			})
    69  		})
    70  
    71  		When("the space exists", func() {
    72  			When("the --guid flag is used", func() {
    73  				It("displays the space guid", func() {
    74  					session := helpers.CF("space", "--guid", spaceName)
    75  					Eventually(session).Should(Say(`[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}`))
    76  					Eventually(session).Should(Exit(0))
    77  				})
    78  			})
    79  
    80  			When("the --guid flag is not used", func() {
    81  				When("no flags are used", func() {
    82  					var (
    83  						appName              string
    84  						isolationSegmentName string
    85  					)
    86  
    87  					BeforeEach(func() {
    88  						appName = helpers.PrefixedRandomName("app")
    89  						helpers.WithHelloWorldApp(func(appDir string) {
    90  							Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0))
    91  						})
    92  					})
    93  
    94  					It("displays a table with space name, org and apps", func() {
    95  						session := helpers.CF("space", spaceName)
    96  						userName, _ := helpers.GetCredentials()
    97  						Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, spaceName, orgName, userName))
    98  
    99  						Eventually(session).Should(Say(`name:\s+%s`, spaceName))
   100  						Eventually(session).Should(Say(`org:\s+%s`, orgName))
   101  						Eventually(session).Should(Say(`apps:\s+%s`, appName))
   102  						Eventually(session).Should(Say(`services:`))
   103  						Eventually(session).Should(Exit(0))
   104  					})
   105  
   106  					When("isolations segments are enabled", func() {
   107  						BeforeEach(func() {
   108  							isolationSegmentName = helpers.NewIsolationSegmentName()
   109  							Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   110  							Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName)).Should(Exit(0))
   111  							Eventually(helpers.CF("set-space-isolation-segment", spaceName, isolationSegmentName)).Should(Exit(0))
   112  						})
   113  
   114  						It("displays the isolation segment in the table", func() {
   115  							session := helpers.CF("space", spaceName)
   116  							userName, _ := helpers.GetCredentials()
   117  
   118  							Eventually(session).Should(Say(`Getting info for space %s in org %s as %s\.\.\.`, spaceName, orgName, userName))
   119  							Eventually(session).Should(Say(`isolation segment:\s+%s`, isolationSegmentName))
   120  						})
   121  					})
   122  				})
   123  
   124  				When("the space does not have an isolation segment and its org has a default isolation segment", func() {
   125  					var orgIsolationSegmentName string
   126  
   127  					BeforeEach(func() {
   128  						orgIsolationSegmentName = helpers.NewIsolationSegmentName()
   129  						Eventually(helpers.CF("create-isolation-segment", orgIsolationSegmentName)).Should(Exit(0))
   130  						Eventually(helpers.CF("enable-org-isolation", orgName, orgIsolationSegmentName)).Should(Exit(0))
   131  						Eventually(helpers.CF("set-org-default-isolation-segment", orgName, orgIsolationSegmentName)).Should(Exit(0))
   132  					})
   133  
   134  					It("shows the org default isolation segment", func() {
   135  						session := helpers.CF("space", spaceName)
   136  						Eventually(session).Should(Say(`isolation segment:\s+%s \(org default\)`, orgIsolationSegmentName))
   137  						Eventually(session).Should(Exit(0))
   138  					})
   139  				})
   140  
   141  				When("the space has service instances", func() {
   142  					var (
   143  						service             string
   144  						servicePlan         string
   145  						serviceInstanceName string
   146  						broker              *fakeservicebroker.FakeServiceBroker
   147  					)
   148  
   149  					BeforeEach(func() {
   150  						broker = fakeservicebroker.New().EnsureBrokerIsAvailable()
   151  						service = broker.ServiceName()
   152  						servicePlan = broker.ServicePlanName()
   153  						serviceInstanceName = helpers.NewServiceInstanceName()
   154  						Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
   155  						Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName)).Should(Exit(0))
   156  					})
   157  
   158  					AfterEach(func() {
   159  						broker.Destroy()
   160  					})
   161  
   162  					It("shows the service instance", func() {
   163  						session := helpers.CF("space", spaceName)
   164  						Eventually(session).Should(Say(`services:\s+%s`, serviceInstanceName))
   165  						Eventually(session).Should(Exit(0))
   166  					})
   167  				})
   168  			})
   169  		})
   170  	})
   171  })