github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/org_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"sort"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     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("org 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  		Context("when --help flag is set", func() {
    27  			It("Displays command usage to output", func() {
    28  				session := helpers.CF("org", "--help")
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("org - Show org info"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say("cf org ORG [--guid]"))
    33  				Eventually(session).Should(Say("OPTIONS:"))
    34  				Eventually(session).Should(Say("--guid\\s+Retrieve and display the given org's guid.  All other output for the org is suppressed."))
    35  				Eventually(session).Should(Say("SEE ALSO:"))
    36  				Eventually(session).Should(Say("org-users, orgs"))
    37  				Eventually(session).Should(Exit(0))
    38  			})
    39  		})
    40  	})
    41  
    42  	Context("when the environment is not setup correctly", func() {
    43  		It("fails with the appropriate errors", func() {
    44  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "org", "org-name")
    45  		})
    46  	})
    47  
    48  	Context("when the environment is set up correctly", func() {
    49  		BeforeEach(func() {
    50  			helpers.LoginCF()
    51  		})
    52  
    53  		Context("when the org does not exist", func() {
    54  			It("displays org not found and exits 1", func() {
    55  				session := helpers.CF("org", orgName)
    56  				userName, _ := helpers.GetCredentials()
    57  				Eventually(session).Should(Say("Getting info for org %s as %s\\.\\.\\.", orgName, userName))
    58  				Eventually(session).Should(Say("FAILED"))
    59  				Eventually(session.Err).Should(Say("Organization '%s' not found.", orgName))
    60  				Eventually(session).Should(Exit(1))
    61  			})
    62  		})
    63  
    64  		Context("when the org exists", func() {
    65  			BeforeEach(func() {
    66  				helpers.SetupCF(orgName, spaceName)
    67  			})
    68  
    69  			AfterEach(func() {
    70  				helpers.QuickDeleteOrg(orgName)
    71  			})
    72  
    73  			Context("when the --guid flag is used", func() {
    74  				It("displays the org guid", func() {
    75  					session := helpers.CF("org", "--guid", orgName)
    76  					Eventually(session).Should(Say("[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}"))
    77  					Eventually(session).Should(Exit(0))
    78  				})
    79  			})
    80  
    81  			Context("when no flags are used", func() {
    82  				var (
    83  					domainName string
    84  					quotaName  string
    85  					spaceName2 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  				})
   103  
   104  				It("displays a table with org domains, quotas, spaces, space quotas and isolation segments, and exits 0", func() {
   105  					session := helpers.CF("org", orgName)
   106  					userName, _ := helpers.GetCredentials()
   107  					Eventually(session).Should(Say("Getting info for org %s as %s\\.\\.\\.", orgName, userName))
   108  
   109  					Eventually(session).Should(Say("name:\\s+%s", orgName))
   110  
   111  					domainsSorted := []string{helpers.DefaultSharedDomain(), domainName}
   112  					sort.Strings(domainsSorted)
   113  					Eventually(session).Should(Say("domains:.+%s,.+%s", domainsSorted[0], domainsSorted[1]))
   114  
   115  					Eventually(session).Should(Say("quota:\\s+%s", quotaName))
   116  
   117  					spacesSorted := []string{spaceName, spaceName2}
   118  					sort.Strings(spacesSorted)
   119  					Eventually(session).Should(Say("spaces:\\s+%s,.* %s", spacesSorted[0], spacesSorted[1]))
   120  
   121  					Eventually(session).Should(Exit(0))
   122  				})
   123  
   124  				Context("when isolation segments are available", func() {
   125  					var isolationSegmentsSorted []string
   126  
   127  					BeforeEach(func() {
   128  						helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3)
   129  
   130  						isolationSegmentName1 := helpers.NewIsolationSegmentName()
   131  						Eventually(helpers.CF("create-isolation-segment", isolationSegmentName1)).Should(Exit(0))
   132  						Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName1)).Should(Exit(0))
   133  
   134  						isolationSegmentName2 := helpers.NewIsolationSegmentName()
   135  						Eventually(helpers.CF("create-isolation-segment", isolationSegmentName2)).Should(Exit(0))
   136  						Eventually(helpers.CF("enable-org-isolation", orgName, isolationSegmentName2)).Should(Exit(0))
   137  
   138  						isolationSegmentsSorted = []string{isolationSegmentName1, isolationSegmentName2}
   139  						sort.Strings(isolationSegmentsSorted)
   140  
   141  						Eventually(helpers.CF("set-org-default-isolation-segment", orgName, isolationSegmentsSorted[0])).Should(Exit(0))
   142  					})
   143  
   144  					It("displays isolation segment information in the org table", func() {
   145  						session := helpers.CF("org", orgName)
   146  
   147  						Eventually(session).Should(Say("isolation segments:\\s+.*%s \\(default\\),.* %s", isolationSegmentsSorted[0], isolationSegmentsSorted[1]))
   148  					})
   149  				})
   150  			})
   151  		})
   152  	})
   153  })