github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/delete_org_quota_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("delete-org-quota command", func() {
    12  	var (
    13  		quotaName string
    14  		userName  string
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		userName = helpers.LoginCF()
    19  		quotaName = helpers.QuotaName()
    20  	})
    21  
    22  	When("the --help flag is passed", func() {
    23  		It("Displays the appropriate help text", func() {
    24  			session := helpers.CF("delete-org-quota", "--help")
    25  			Eventually(session).Should(Say("NAME:"))
    26  			Eventually(session).Should(Say("delete-org-quota - Delete an organization quota"))
    27  			Eventually(session).Should(Say("\n"))
    28  			Eventually(session).Should(Say("USAGE:"))
    29  			Eventually(session).Should(Say(`cf delete-org-quota QUOTA \[-f]`))
    30  			Eventually(session).Should(Say("\n"))
    31  			Eventually(session).Should(Say("ALIAS:"))
    32  			Eventually(session).Should(Say("delete-quota"))
    33  			Eventually(session).Should(Say("OPTIONS:"))
    34  			Eventually(session).Should(Say(`--force, -f\s+Force deletion without confirmation`))
    35  			Eventually(session).Should(Say("\n"))
    36  			Eventually(session).Should(Say("SEE ALSO:"))
    37  			Eventually(session).Should(Say("org-quotas"))
    38  			Eventually(session).Should(Exit(0))
    39  		})
    40  	})
    41  
    42  	When("the quota name is not provided", func() {
    43  		It("displays an error and help", func() {
    44  			session := helpers.CF("delete-org-quota")
    45  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `QUOTA` was not provided"))
    46  			Eventually(session).Should(Say("USAGE"))
    47  			Eventually(session).Should(Exit(1))
    48  		})
    49  	})
    50  
    51  	When("the quota doesn't exist", func() {
    52  		It("displays a warning and exits 0", func() {
    53  			session := helpers.CF("delete-org-quota", "-f", "nonexistent-quota")
    54  			Eventually(session).Should(Say(`Deleting org quota nonexistent-quota as %s\.\.\.`, userName))
    55  			Eventually(session).Should(Say("OK"))
    56  			Eventually(session.Err).Should(Say(`Organization quota with name 'nonexistent-quota' not found\.`))
    57  			Eventually(session).Should(Exit(0))
    58  		})
    59  	})
    60  
    61  	Context("the -f flag is provided", func() {
    62  		BeforeEach(func() {
    63  			session := helpers.CF("create-org-quota", quotaName)
    64  			Eventually(session).Should(Exit(0))
    65  		})
    66  
    67  		It("deletes the specified quota", func() {
    68  			session := helpers.CF("delete-org-quota", quotaName, "-f")
    69  			Eventually(session).Should(Say(`Deleting org quota %s as %s\.\.\.`, quotaName, userName))
    70  			Eventually(session).Should(Say("OK"))
    71  			Eventually(session).Should(Exit(0))
    72  		})
    73  	})
    74  
    75  	When("the -f flag not is provided", func() {
    76  		var buffer *Buffer
    77  
    78  		BeforeEach(func() {
    79  			buffer = NewBuffer()
    80  			session := helpers.CF("create-org-quota", quotaName)
    81  			Eventually(session).Should(Exit(0))
    82  		})
    83  
    84  		When("the user enters 'y'", func() {
    85  			BeforeEach(func() {
    86  				_, err := buffer.Write([]byte("y\n"))
    87  				Expect(err).ToNot(HaveOccurred())
    88  			})
    89  
    90  			It("deletes the quota", func() {
    91  				session := helpers.CFWithStdin(buffer, "delete-org-quota", quotaName)
    92  				Eventually(session).Should(Say(`Deleting org quota %s as %s\.\.\.`, quotaName, userName))
    93  				Eventually(session).Should(Say("OK"))
    94  				Eventually(session).Should(Exit(0))
    95  
    96  				session = helpers.CF("org-quotas")
    97  				Eventually(session).Should(Exit(0))
    98  				Expect(session.Out.Contents()).NotTo(ContainSubstring(quotaName))
    99  			})
   100  		})
   101  
   102  		When("the user enters 'n'", func() {
   103  			BeforeEach(func() {
   104  				_, err := buffer.Write([]byte("n\n"))
   105  				Expect(err).ToNot(HaveOccurred())
   106  			})
   107  
   108  			It("does not delete the quota", func() {
   109  				session := helpers.CFWithStdin(buffer, "delete-org-quota", quotaName)
   110  				Eventually(session).Should(Say(`Organization quota '%s' has not been deleted\.`, quotaName))
   111  				Eventually(session).Should(Exit(0))
   112  
   113  				session = helpers.CF("org-quotas")
   114  				Eventually(session).Should(Say(quotaName))
   115  				Eventually(session).Should(Exit(0))
   116  			})
   117  		})
   118  
   119  		When("the user enters the default input (hits return)", func() {
   120  			BeforeEach(func() {
   121  				_, err := buffer.Write([]byte("\n"))
   122  				Expect(err).ToNot(HaveOccurred())
   123  			})
   124  
   125  			It("does not delete the quota", func() {
   126  				session := helpers.CFWithStdin(buffer, "delete-org-quota", quotaName)
   127  				Eventually(session).Should(Say(`Organization quota '%s' has not been deleted\.`, quotaName))
   128  				Eventually(session).Should(Exit(0))
   129  
   130  				session = helpers.CF("org-quotas")
   131  				Eventually(session).Should(Say(quotaName))
   132  				Eventually(session).Should(Exit(0))
   133  			})
   134  		})
   135  	})
   136  })