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