github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/org_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"sort"
     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("org command", func() {
    14  	var (
    15  		orgName   string
    16  		spaceName string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  	})
    23  
    24  	Describe("help", func() {
    25  		When("--help flag is set", func() {
    26  			It("Displays command usage to output", func() {
    27  				session := helpers.CF("org", "--help")
    28  				Eventually(session).Should(Say("NAME:"))
    29  				Eventually(session).Should(Say("org - Show org info"))
    30  				Eventually(session).Should(Say("USAGE:"))
    31  				Eventually(session).Should(Say("cf org ORG [--guid]"))
    32  				Eventually(session).Should(Say("OPTIONS:"))
    33  				Eventually(session).Should(Say(`--guid\s+Retrieve and display the given org's guid.  All other output for the org is suppressed.`))
    34  				Eventually(session).Should(Say("SEE ALSO:"))
    35  				Eventually(session).Should(Say("org-users, orgs"))
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	When("the environment is not setup correctly", func() {
    42  		It("fails with the appropriate errors", func() {
    43  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "org", "org-name")
    44  		})
    45  	})
    46  
    47  	When("the environment is set up correctly", func() {
    48  		BeforeEach(func() {
    49  			helpers.LoginCF()
    50  		})
    51  
    52  		When("the org does not exist", func() {
    53  			It("displays org not found and exits 1", func() {
    54  				session := helpers.CF("org", orgName)
    55  				userName, _ := helpers.GetCredentials()
    56  				Eventually(session).Should(Say(`Getting info for org %s as %s\.\.\.`, orgName, userName))
    57  				Eventually(session).Should(Say("FAILED"))
    58  				Eventually(session.Err).Should(Say("Organization '%s' not found.", orgName))
    59  				Eventually(session).Should(Exit(1))
    60  			})
    61  		})
    62  
    63  		When("the org exists", func() {
    64  			BeforeEach(func() {
    65  				helpers.SetupCF(orgName, spaceName)
    66  			})
    67  
    68  			AfterEach(func() {
    69  				helpers.QuickDeleteOrg(orgName)
    70  			})
    71  
    72  			When("the --guid flag is used", func() {
    73  				It("displays the org guid", func() {
    74  					session := helpers.CF("org", "--guid", orgName)
    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("no flags are used", func() {
    81  				var (
    82  					domainName string
    83  					quotaName  string
    84  					spaceName2 string
    85  				)
    86  
    87  				BeforeEach(func() {
    88  					domainName = helpers.NewDomainName("")
    89  					domain := helpers.NewDomain(orgName, domainName)
    90  					domain.Create()
    91  
    92  					quotaName = helpers.QuotaName()
    93  					session := helpers.CF("create-quota", quotaName)
    94  					Eventually(session).Should(Exit(0))
    95  					session = helpers.CF("set-quota", orgName, quotaName)
    96  					Eventually(session).Should(Exit(0))
    97  
    98  					spaceName2 = helpers.NewSpaceName()
    99  					helpers.CreateSpace(spaceName2)
   100  
   101  				})
   102  
   103  				It("displays a table with org domains, quotas, spaces, space quotas and isolation segments, and exits 0", func() {
   104  					session := helpers.CF("org", orgName)
   105  					userName, _ := helpers.GetCredentials()
   106  					Eventually(session).Should(Say(`Getting info for org %s as %s\.\.\.`, orgName, userName))
   107  
   108  					Eventually(session).Should(Say(`name:\s+%s`, orgName))
   109  
   110  					domainsSorted := []string{helpers.DefaultSharedDomain(), domainName}
   111  					sort.Strings(domainsSorted)
   112  					Eventually(session).Should(Say("domains:.+%s,.+%s", domainsSorted[0], domainsSorted[1]))
   113  
   114  					Eventually(session).Should(Say(`quota:\s+%s`, quotaName))
   115  
   116  					spacesSorted := []string{spaceName, spaceName2}
   117  					sort.Strings(spacesSorted)
   118  					Eventually(session).Should(Say(`spaces:\s+%s,.* %s`, spacesSorted[0], spacesSorted[1]))
   119  
   120  					Eventually(session).Should(Exit(0))
   121  				})
   122  
   123  				When("isolation segments are available", func() {
   124  					var isolationSegmentsSorted []string
   125  
   126  					BeforeEach(func() {
   127  						isolationSegmentName1 := helpers.NewIsolationSegmentName()
   128  						Eventually(helpers.CF("create-isolation-segment", isolationSegmentName1)).Should(Exit(0))
   129  						Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName1)).Should(Exit(0))
   130  
   131  						isolationSegmentName2 := helpers.NewIsolationSegmentName()
   132  						Eventually(helpers.CF("create-isolation-segment", isolationSegmentName2)).Should(Exit(0))
   133  						Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName2)).Should(Exit(0))
   134  
   135  						isolationSegmentsSorted = []string{isolationSegmentName1, isolationSegmentName2}
   136  						sort.Strings(isolationSegmentsSorted)
   137  
   138  						Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentsSorted[0])).Should(Exit(0))
   139  					})
   140  
   141  					It("displays isolation segment information in the org table", func() {
   142  						session := helpers.CF("org", orgName)
   143  
   144  						Eventually(session).Should(Say(`isolation segments:\s+.*%s \(default\),.* %s`, isolationSegmentsSorted[0], isolationSegmentsSorted[1]))
   145  					})
   146  				})
   147  			})
   148  		})
   149  	})
   150  })