github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/create_org_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("create-org command", func() {
    13  	var (
    14  		orgNameNew string
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		orgNameNew = helpers.NewOrgName()
    19  	})
    20  
    21  	Describe("help", func() {
    22  		When("--help flag is set", func() {
    23  			It("appears in cf help -a", func() {
    24  				session := helpers.CF("help", "-a")
    25  				Eventually(session).Should(Exit(0))
    26  				Expect(session).To(HaveCommandInCategoryWithDescription("create-org", "ORGS", "Create an org"))
    27  			})
    28  
    29  			It("Displays command usage to output", func() {
    30  				session := helpers.CF("create-org", "--help")
    31  				Eventually(session).Should(Say("NAME:"))
    32  				Eventually(session).Should(Say("create-org - Create an org"))
    33  				Eventually(session).Should(Say("USAGE:"))
    34  				Eventually(session).Should(Say(`cf create-org ORG \[-q ORG_QUOTA\]`))
    35  				Eventually(session).Should(Say("ALIAS:"))
    36  				Eventually(session).Should(Say(`co`))
    37  				Eventually(session).Should(Say("OPTIONS:"))
    38  				Eventually(session).Should(Say(`--quota, -q\s+Quota to assign to the newly created org`))
    39  				Eventually(session).Should(Say("SEE ALSO:"))
    40  				Eventually(session).Should(Say("create-space, org-quotas, orgs, set-org-role"))
    41  				Eventually(session).Should(Exit(0))
    42  			})
    43  		})
    44  
    45  		When("the org name is not provided", func() {
    46  			It("tells the user that the org name is required, prints help text, and exits 1", func() {
    47  				session := helpers.CF("create-org")
    48  
    49  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided"))
    50  				Eventually(session).Should(Say("NAME:"))
    51  				Eventually(session).Should(Exit(1))
    52  			})
    53  		})
    54  	})
    55  
    56  	When("the environment is not setup correctly", func() {
    57  		It("fails with the appropriate errors", func() {
    58  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-org", orgNameNew)
    59  		})
    60  	})
    61  
    62  	When("the environment is set up correctly", func() {
    63  		BeforeEach(func() {
    64  			helpers.LoginCF()
    65  		})
    66  
    67  		AfterEach(func() {
    68  			helpers.QuickDeleteOrg(orgNameNew)
    69  		})
    70  
    71  		When("the org does not exist", func() {
    72  			It("creates the org", func() {
    73  				session := helpers.CF("create-org", orgNameNew)
    74  				userName, _ := helpers.GetCredentials()
    75  				Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName))
    76  				Eventually(session).Should(Say("OK"))
    77  
    78  				Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as %s...", userName, orgNameNew, userName))
    79  				Eventually(session).Should(Say("OK"))
    80  
    81  				Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgNameNew))
    82  				Eventually(session).Should(Exit(0))
    83  
    84  				session = helpers.CF("org", orgNameNew)
    85  				Eventually(session).Should(Say(`name:\s+%s`, orgNameNew))
    86  				Eventually(session).Should(Exit(0))
    87  			})
    88  		})
    89  
    90  		When("the org already exists", func() {
    91  			BeforeEach(func() {
    92  				Eventually(helpers.CF("create-org", orgNameNew)).Should(Exit(0))
    93  			})
    94  
    95  			It("fails to create the org", func() {
    96  				session := helpers.CF("create-org", orgNameNew)
    97  				userName, _ := helpers.GetCredentials()
    98  				Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName))
    99  				Eventually(session).Should(Say(`Organization '%s' already exists\.`, orgNameNew))
   100  				Eventually(session).Should(Say("OK"))
   101  				Eventually(session).Should(Exit(0))
   102  			})
   103  		})
   104  
   105  		When("the -quota flag is passed", func() {
   106  			When("the quota does not exist", func() {
   107  				var (
   108  					quotaName = "garb-quota"
   109  				)
   110  
   111  				It("makes an org with the default quota and informs the user setting the quota has failed", func() {
   112  					session := helpers.CF("create-org", orgNameNew, "-q", quotaName)
   113  					userName, _ := helpers.GetCredentials()
   114  					Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName))
   115  					Eventually(session).Should(Say("OK"))
   116  
   117  					Eventually(session).Should(Say("Setting org quota %s to org %s as %s...", quotaName, orgNameNew, userName))
   118  					Eventually(session.Err).Should(Say("Organization quota with name '%s' not found.", quotaName))
   119  					Eventually(session).Should(Say("FAILED"))
   120  
   121  					session = helpers.CF("org", orgNameNew)
   122  					Eventually(session).Should(Say(`name:\s+%s`, orgNameNew))
   123  					Eventually(session).Should(Say(`quota:\s+%s`, `default`))
   124  					Eventually(session).Should(Exit(0))
   125  				})
   126  			})
   127  
   128  			When("the quota exists", func() {
   129  				var (
   130  					quotaName = helpers.QuotaName()
   131  				)
   132  
   133  				BeforeEach(func() {
   134  					Eventually(helpers.CF("create-org-quota", quotaName)).Should(Exit(0))
   135  				})
   136  
   137  				It("makes an org with the given quota", func() {
   138  					session := helpers.CF("create-org", orgNameNew, "-q", quotaName)
   139  					userName, _ := helpers.GetCredentials()
   140  					Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName))
   141  					Eventually(session).Should(Say("OK"))
   142  
   143  					Eventually(session).Should(Say("Setting org quota %s to org %s as %s...", quotaName, orgNameNew, userName))
   144  					Eventually(session).Should(Say("OK"))
   145  
   146  					Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as %s...", userName, orgNameNew, userName))
   147  					Eventually(session).Should(Say("OK"))
   148  
   149  					Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgNameNew))
   150  					Eventually(session).Should(Exit(0))
   151  
   152  					session = helpers.CF("org", orgNameNew)
   153  					Eventually(session).Should(Say(`name:\s+%s`, orgNameNew))
   154  					Eventually(session).Should(Say(`quota:\s+%s`, quotaName))
   155  					Eventually(session).Should(Exit(0))
   156  				})
   157  			})
   158  		})
   159  	})
   160  })