github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/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  		Context("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  	Context("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  	Context("when the environment is set up correctly", func() {
    48  		BeforeEach(func() {
    49  			helpers.LoginCF()
    50  		})
    51  
    52  		Context("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  		Context("when the org exists", func() {
    64  			BeforeEach(func() {
    65  				setupCF(orgName, spaceName)
    66  			})
    67  
    68  			AfterEach(func() {
    69  				helpers.QuickDeleteOrg(orgName)
    70  			})
    71  
    72  			Context("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  			Context("when no flags are used", func() {
    81  				var (
    82  					domainName              string
    83  					quotaName               string
    84  					spaceName2              string
    85  					isolationSegmentsSorted []string
    86  				)
    87  
    88  				BeforeEach(func() {
    89  					domainName = helpers.DomainName("")
    90  					domain := helpers.NewDomain(orgName, domainName)
    91  					domain.Create()
    92  
    93  					quotaName = helpers.QuotaName()
    94  					session := helpers.CF("create-quota", quotaName)
    95  					Eventually(session).Should(Exit(0))
    96  					session = helpers.CF("set-quota", orgName, quotaName)
    97  					Eventually(session).Should(Exit(0))
    98  
    99  					spaceName2 = helpers.NewSpaceName()
   100  					helpers.CreateSpace(spaceName2)
   101  
   102  					isolationSegmentName1 := helpers.NewIsolationSegmentName()
   103  					Eventually(helpers.CF("create-isolation-segment", isolationSegmentName1)).Should(Exit(0))
   104  					Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName1)).Should(Exit(0))
   105  
   106  					isolationSegmentName2 := helpers.NewIsolationSegmentName()
   107  					Eventually(helpers.CF("create-isolation-segment", isolationSegmentName2)).Should(Exit(0))
   108  					Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName2)).Should(Exit(0))
   109  
   110  					isolationSegmentsSorted = []string{isolationSegmentName1, isolationSegmentName2}
   111  					sort.Strings(isolationSegmentsSorted)
   112  
   113  					Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentsSorted[0])).Should(Exit(0))
   114  				})
   115  
   116  				It("displays a table with org domains, quotas, spaces, space quotas and isolation segments, and exits 0", func() {
   117  					session := helpers.CF("org", orgName)
   118  					userName, _ := helpers.GetCredentials()
   119  					Eventually(session).Should(Say("Getting info for org %s as %s\\.\\.\\.", orgName, userName))
   120  
   121  					Eventually(session).Should(Say("name:\\s+%s", orgName))
   122  
   123  					domainsSorted := []string{defaultSharedDomain(), domainName}
   124  					sort.Strings(domainsSorted)
   125  					Eventually(session).Should(Say("domains:.+%s,.+%s", domainsSorted[0], domainsSorted[1]))
   126  
   127  					Eventually(session).Should(Say("quota:\\s+%s", quotaName))
   128  
   129  					spacesSorted := []string{spaceName, spaceName2}
   130  					sort.Strings(spacesSorted)
   131  					Eventually(session).Should(Say("spaces:\\s+%s,.* %s", spacesSorted[0], spacesSorted[1]))
   132  
   133  					Eventually(session).Should(Say("isolation segments:\\s+.*%s \\(default\\),.* %s", isolationSegmentsSorted[0], isolationSegmentsSorted[1]))
   134  
   135  					Eventually(session).Should(Exit(0))
   136  				})
   137  			})
   138  		})
   139  	})
   140  })