github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/set_space_quota_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("set-space-quota command", func() {
    13  	var (
    14  		orgName   string
    15  		spaceName string
    16  		quotaName string
    17  		userName  string
    18  	)
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  
    23  		helpers.SetupCF(orgName, spaceName)
    24  		quotaName = helpers.QuotaName()
    25  		session := helpers.CF("create-space-quota", quotaName)
    26  		Eventually(session).Should(Exit(0))
    27  	})
    28  
    29  	When("the environment is not setup correctly", func() {
    30  		It("fails with the appropriate errors", func() {
    31  			helpers.CheckEnvironmentTargetedCorrectly(true, false, orgName, "set-space-quota", spaceName, quotaName)
    32  		})
    33  	})
    34  
    35  	When("the environment is setup correctly", func() {
    36  		AfterEach(func() {
    37  			helpers.QuickDeleteOrg(orgName)
    38  		})
    39  
    40  		BeforeEach(func() {
    41  			userName, _ = helpers.GetCredentials()
    42  		})
    43  
    44  		Describe("help", func() {
    45  			When("--help flag is set", func() {
    46  				It("appears in cf help -a", func() {
    47  					session := helpers.CF("help", "-a")
    48  					Eventually(session).Should(Exit(0))
    49  					Expect(session).To(HaveCommandInCategoryWithDescription("set-space-quota", "SPACE ADMIN", "Assign a quota to a space"))
    50  				})
    51  
    52  				It("Displays command usage to output", func() {
    53  					session := helpers.CF("set-space-quota", "--help")
    54  					Eventually(session).Should(Say("NAME:"))
    55  					Eventually(session).Should(Say("set-space-quota - Assign a quota to a space"))
    56  					Eventually(session).Should(Say("USAGE:"))
    57  					Eventually(session).Should(Say("cf set-space-quota SPACE QUOTA"))
    58  					Eventually(session).Should(Say("SEE ALSO:"))
    59  					Eventually(session).Should(Say("space, space-quotas, spaces"))
    60  					Eventually(session).Should(Exit(0))
    61  				})
    62  			})
    63  		})
    64  
    65  		When("valid arguments are provided", func() {
    66  			It("sets the quota on a space", func() {
    67  				session := helpers.CF("set-space-quota", spaceName, quotaName)
    68  				Eventually(session).Should(Say("Setting space quota %s to space %s as %s...", quotaName, spaceName, userName))
    69  				Eventually(session).Should(Say("OK"))
    70  				Eventually(session).Should(Exit(0))
    71  
    72  				session = helpers.CF("space", spaceName)
    73  				Eventually(session).Should(Say(`(?i)quota:\s+%s`, quotaName))
    74  				Eventually(session).Should(Exit(0))
    75  			})
    76  
    77  			When("the quota is already applied to the space", func() {
    78  				BeforeEach(func() {
    79  					session := helpers.CF("set-space-quota", spaceName, quotaName)
    80  					Eventually(session).Should(Exit(0))
    81  				})
    82  
    83  				It("sets the quota on the space", func() {
    84  					session := helpers.CF("set-space-quota", spaceName, quotaName)
    85  					Eventually(session).Should(Say("Setting space quota %s to space %s as %s...", quotaName, spaceName, userName))
    86  					Eventually(session).Should(Say("OK"))
    87  					Eventually(session).Should(Exit(0))
    88  				})
    89  			})
    90  		})
    91  
    92  		When("invalid arguments are provided", func() {
    93  			It("fails and informs the user an invalid quota was provided", func() {
    94  				session := helpers.CF("set-space-quota", spaceName, "fake-name")
    95  				Eventually(session).Should(Say("FAILED"))
    96  				Eventually(session.Err).Should(Say("Space quota with name '%s' not found.", "fake-name"))
    97  				Eventually(session).Should(Exit(1))
    98  			})
    99  
   100  			It("fails and informs the user an invalid space was provided", func() {
   101  				session := helpers.CF("set-space-quota", "fake-name", quotaName)
   102  				Eventually(session).Should(Say("FAILED"))
   103  				Eventually(session.Err).Should(Say("Space 'fake-name' not found."))
   104  				Eventually(session).Should(Exit(1))
   105  			})
   106  		})
   107  
   108  		When("the incorrect number of positional arguments are provided", func() {
   109  			It("fails and informs the user a positional argument is missing", func() {
   110  				session := helpers.CF("set-space-quota", spaceName)
   111  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `QUOTA` was not provided"))
   112  				Eventually(session).Should(Say("NAME:"))
   113  				Eventually(session).Should(Exit(1))
   114  			})
   115  
   116  			It("fails and reminds the user only two positional args are needed", func() {
   117  				session := helpers.CF("set-space-quota", spaceName, quotaName, "extra")
   118  				Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "extra"`))
   119  				Eventually(session).Should(Say("NAME:"))
   120  				Eventually(session).Should(Exit(1))
   121  			})
   122  		})
   123  	})
   124  })