github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/unset_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("unset-space-quota command", func() {
    13  	var (
    14  		orgName        string
    15  		spaceQuotaName string
    16  		spaceName      string
    17  	)
    18  
    19  	Describe("help", func() {
    20  		When("--help flag is set", func() {
    21  			It("appears in cf help -a", func() {
    22  				session := helpers.CF("help", "-a")
    23  				Eventually(session).Should(Exit(0))
    24  				Expect(session).To(HaveCommandInCategoryWithDescription("unset-space-quota", "SPACE ADMIN", "Unassign a quota from a space"))
    25  			})
    26  
    27  			It("Displays command usage to output", func() {
    28  				session := helpers.CF("unset-space-quota", "--help")
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("unset-space-quota - Unassign a quota from a space"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say(`cf unset-space-quota SPACE SPACE_QUOTA`))
    33  				Eventually(session).Should(Say("SEE ALSO:"))
    34  				Eventually(session).Should(Say("space\n"))
    35  				Eventually(session).Should(Exit(0))
    36  			})
    37  		})
    38  	})
    39  
    40  	When("the environment is not setup correctly", func() {
    41  		It("fails with the appropriate errors", func() {
    42  			helpers.CheckEnvironmentTargetedCorrectly(true, false, orgName, "unset-space-quota", spaceName, spaceQuotaName)
    43  		})
    44  	})
    45  
    46  	When("the environment is set up correctly", func() {
    47  		var (
    48  			userName string
    49  		)
    50  
    51  		BeforeEach(func() {
    52  			userName = helpers.LoginCF()
    53  			orgName = helpers.CreateAndTargetOrg()
    54  			spaceQuotaName = helpers.QuotaName()
    55  			session := helpers.CF("create-space-quota", spaceQuotaName)
    56  			Eventually(session).Should(Exit(0))
    57  			spaceName = helpers.NewSpaceName()
    58  			helpers.CreateSpace(spaceName)
    59  		})
    60  
    61  		AfterEach(func() {
    62  			helpers.QuickDeleteOrg(orgName)
    63  		})
    64  
    65  		When("no arguments are provided", func() {
    66  			It("tells the user that the space and quota are required, prints help text, and exits 1", func() {
    67  				session := helpers.CF("unset-space-quota")
    68  
    69  				Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SPACE_NAME` and `SPACE_QUOTA` were not provided"))
    70  				Eventually(session).Should(Say("NAME:"))
    71  				Eventually(session).Should(Exit(1))
    72  			})
    73  		})
    74  
    75  		When("only one argument is provided", func() {
    76  			It("tells the user that the quota name is required, prints help text, and exits 1", func() {
    77  				session := helpers.CF("unset-space-quota", spaceName)
    78  
    79  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE_QUOTA` was not provided"))
    80  				Eventually(session).Should(Say("NAME:"))
    81  				Eventually(session).Should(Exit(1))
    82  			})
    83  		})
    84  
    85  		When("a nonexistent flag is provided", func() {
    86  			It("tells the user that the flag is invalid", func() {
    87  				session := helpers.CF("unset-space-quota", "--nonexistent")
    88  
    89  				Eventually(session.Err).Should(Say("Incorrect Usage: unknown flag `nonexistent'"))
    90  				Eventually(session).Should(Say("NAME:"))
    91  				Eventually(session).Should(Exit(1))
    92  			})
    93  		})
    94  
    95  		When("the space does not exist", func() {
    96  			It("fails and reports that the space could not be found", func() {
    97  				session := helpers.CF("unset-space-quota", "bad-space-name", spaceQuotaName)
    98  				Eventually(session).Should(Say("FAILED"))
    99  				Eventually(session.Err).Should(Say(`Space 'bad-space-name' not found\.`))
   100  				Eventually(session).Should(Exit(1))
   101  			})
   102  		})
   103  
   104  		When("the quota does not exist", func() {
   105  			It("fails and reports that the quota could not be found", func() {
   106  				session := helpers.CF("unset-space-quota", spaceName, "bad-quota-name")
   107  				Eventually(session).Should(Say("FAILED"))
   108  				Eventually(session.Err).Should(Say(`Space quota with name 'bad-quota-name' not found\.`))
   109  				Eventually(session).Should(Exit(1))
   110  			})
   111  		})
   112  
   113  		When("the quota is not associated with the space", func() {
   114  			It("succeeds", func() {
   115  				session := helpers.CF("unset-space-quota", spaceName, spaceQuotaName)
   116  				Eventually(session).Should(Say(`Unassigning space quota %s from space %s as %s\.\.\.`, spaceQuotaName, spaceName, userName))
   117  				Eventually(session.Err).Should(Say("Unable to remove quota from space with guid '[a-z0-9-]+'. Ensure the space quota is applied to this space."))
   118  				Eventually(session).Should(Say("FAILED"))
   119  				Eventually(session).Should(Exit(1))
   120  			})
   121  		})
   122  
   123  		When("the quota is associated with the space", func() {
   124  			BeforeEach(func() {
   125  				session := helpers.CF("set-space-quota", spaceName, spaceQuotaName)
   126  				Eventually(session).Should(Exit(0))
   127  			})
   128  
   129  			It("unsets the quota from the space", func() {
   130  				session := helpers.CF("unset-space-quota", spaceName, spaceQuotaName)
   131  				Eventually(session).Should(Say(`Unassigning space quota %s from space %s as %s\.\.\.`, spaceQuotaName, spaceName, userName))
   132  				Eventually(session).Should(Say("OK"))
   133  				Eventually(session).Should(Exit(0))
   134  			})
   135  		})
   136  	})
   137  })