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

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gbytes"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = Describe("create-org", func() {
    12  	When("invoked with --help", func() {
    13  		It("displays the help information", func() {
    14  			session := helpers.CF("create-org", "--help")
    15  			Eventually(session).Should(Say(`NAME:`))
    16  			Eventually(session).Should(Say(`create-org - Create an org\n`))
    17  			Eventually(session).Should(Say(`\n`))
    18  
    19  			Eventually(session).Should(Say(`USAGE:`))
    20  			Eventually(session).Should(Say(`cf create-org ORG\n`))
    21  			Eventually(session).Should(Say(`\n`))
    22  
    23  			Eventually(session).Should(Say(`OPTIONS:`))
    24  			Eventually(session).Should(Say(`-q\s+Quota to assign to the newly created org \(excluding this option results in assignment of default quota\)`))
    25  			Eventually(session).Should(Say(`\n`))
    26  
    27  			Eventually(session).Should(Say(`SEE ALSO:`))
    28  			Eventually(session).Should(Say(`create-space, orgs, quotas, set-org-role`))
    29  
    30  			Eventually(session).Should(Exit(0))
    31  		})
    32  	})
    33  
    34  	When("the environment is not set up correctly", func() {
    35  		It("fails with the appropriate errors", func() {
    36  			helpers.CheckEnvironmentTargetedCorrectly(false, false, "", "create-org", "some-org")
    37  		})
    38  	})
    39  
    40  	When("logged in as a client", func() {
    41  		var client string
    42  
    43  		BeforeEach(func() {
    44  			client = helpers.LoginCFWithClientCredentials()
    45  		})
    46  
    47  		It("successfully creates an org", func() {
    48  			orgName := helpers.NewOrgName()
    49  			session := helpers.CF("create-org", orgName)
    50  
    51  			Eventually(session.Out).Should(Say(`Creating org %s as %s\.\.\.`, orgName, client))
    52  			Eventually(session.Out).Should(Say(`OK\n\n`))
    53  			Eventually(session.Out).Should(Say(`Assigning role OrgManager to user %s in org %s\.\.\.`, client, orgName))
    54  			Eventually(session.Out).Should(Say(`OK\n\n`))
    55  			Eventually(session.Out).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgName))
    56  			Eventually(session).Should(Exit(0))
    57  		})
    58  	})
    59  
    60  	When("logged in as a user", func() {
    61  		var user string
    62  
    63  		BeforeEach(func() {
    64  			user = helpers.LoginCF()
    65  		})
    66  
    67  		When("the org does not exist yet", func() {
    68  			It("creates the org", func() {
    69  				orgName := helpers.NewOrgName()
    70  				session := helpers.CF("create-org", orgName)
    71  
    72  				Eventually(session.Out).Should(Say(`Creating org %s as %s\.\.\.`, orgName, user))
    73  				Eventually(session.Out).Should(Say(`OK\n\n`))
    74  				Eventually(session.Out).Should(Say(`Assigning role OrgManager to user %s in org %s\.\.\.`, user, orgName))
    75  				Eventually(session.Out).Should(Say(`OK\n\n`))
    76  				Eventually(session.Out).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgName))
    77  				Eventually(session).Should(Exit(0))
    78  			})
    79  
    80  			It("makes the user an org manager", func() {
    81  				orgName := helpers.NewOrgName()
    82  				session := helpers.CF("create-org", orgName)
    83  				Eventually(session).Should(Exit(0))
    84  
    85  				session = helpers.CF("org-users", orgName)
    86  				Eventually(session).Should(Exit(0))
    87  				Expect(session.Out).To(Say(`ORG MANAGER\n\s+%s`, user))
    88  			})
    89  
    90  			When("an existing quota is provided", func() {
    91  				var quotaName string
    92  
    93  				BeforeEach(func() {
    94  					quotaName = helpers.QuotaName()
    95  					session := helpers.CF("create-quota", quotaName)
    96  					Eventually(session).Should(Exit(0))
    97  				})
    98  
    99  				It("creates the org with the provided quota", func() {
   100  					orgName := helpers.NewOrgName()
   101  					session := helpers.CF("create-org", orgName, "-q", quotaName)
   102  					Eventually(session).Should(Exit(0))
   103  
   104  					session = helpers.CF("org", orgName)
   105  					Eventually(session).Should(Exit(0))
   106  					Expect(session.Out).To(Say(`quota:\s+%s`, quotaName))
   107  				})
   108  			})
   109  
   110  			When("a nonexistent quota is provided", func() {
   111  				It("fails with an error and does not create the org", func() {
   112  					orgName := helpers.NewOrgName()
   113  					session := helpers.CF("create-org", orgName, "-q", "no-such-quota")
   114  					Eventually(session.Err).Should(Say("Quota no-such-quota not found"))
   115  					Eventually(session).Should(Say(`FAILED\n`))
   116  					Eventually(session).Should(Exit(1))
   117  
   118  					Eventually(helpers.CF("org", orgName)).Should(Exit(1))
   119  				})
   120  			})
   121  		})
   122  
   123  		When("the org already exists", func() {
   124  			var orgName string
   125  
   126  			BeforeEach(func() {
   127  				orgName = helpers.NewOrgName()
   128  				session := helpers.CF("create-org", orgName)
   129  				Eventually(session).Should(Exit(0))
   130  			})
   131  
   132  			It("warns the user that the org already exists", func() {
   133  				session := helpers.CF("create-org", orgName)
   134  				Eventually(session.Out).Should(Say(`Creating org %s as %s\.\.\.`, orgName, user))
   135  				Eventually(session.Out).Should(Say(`OK\n`))
   136  				Eventually(session.Err).Should(Say("Org %s already exists", orgName))
   137  				Eventually(session).Should(Exit(0))
   138  			})
   139  		})
   140  	})
   141  })