github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/service_brokers_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	"code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub"
     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("service-brokers command", func() {
    13  	Describe("help", func() {
    14  		When("--help flag is set", func() {
    15  			It("Displays command usage to output", func() {
    16  				session := helpers.CF("service-brokers", "--help")
    17  				Eventually(session).Should(Say("NAME:"))
    18  				Eventually(session).Should(Say("service-brokers - List service brokers"))
    19  				Eventually(session).Should(Say("USAGE:"))
    20  				Eventually(session).Should(Say("cf service-brokers"))
    21  				Eventually(session).Should(Say("SEE ALSO:"))
    22  				Eventually(session).Should(Say("delete-service-broker, disable-service-access, enable-service-access"))
    23  				Eventually(session).Should(Exit(0))
    24  			})
    25  		})
    26  	})
    27  
    28  	When("environment is not set up", func() {
    29  		It("displays an error and exits 1", func() {
    30  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "service-brokers")
    31  		})
    32  	})
    33  
    34  	When("the environment is set up correctly", func() {
    35  		var (
    36  			username string
    37  			session  *Session
    38  		)
    39  
    40  		BeforeEach(func() {
    41  			username = helpers.LoginCF()
    42  		})
    43  
    44  		JustBeforeEach(func() {
    45  			session = helpers.CF("service-brokers")
    46  		})
    47  
    48  		When("there is a broker", func() {
    49  			var (
    50  				orgName          string
    51  				spaceName        string
    52  				broker1, broker2 *servicebrokerstub.ServiceBrokerStub
    53  			)
    54  
    55  			BeforeEach(func() {
    56  				orgName = helpers.NewOrgName()
    57  				spaceName = helpers.NewSpaceName()
    58  				helpers.SetupCF(orgName, spaceName)
    59  				broker1 = servicebrokerstub.Register()
    60  				broker2 = servicebrokerstub.Register()
    61  			})
    62  
    63  			AfterEach(func() {
    64  				broker1.Forget()
    65  				broker2.Forget()
    66  				helpers.QuickDeleteOrg(orgName)
    67  			})
    68  
    69  			It("prints a table of service brokers", func() {
    70  				Eventually(session).Should(Say("Getting service brokers as %s...", username))
    71  				Eventually(session).Should(Say(`name\s+url`))
    72  				Eventually(session).Should(Say(`%s\s+%s`, broker1.Name, broker1.URL))
    73  				Eventually(session).Should(Say(`%s\s+%s`, broker2.Name, broker2.URL))
    74  				Eventually(session).Should(Exit(0))
    75  			})
    76  
    77  			When("user is not authorized to see the brokers", func() {
    78  				var unprivilegedUsername string
    79  
    80  				BeforeEach(func() {
    81  					var password string
    82  					unprivilegedUsername, password = helpers.CreateUser()
    83  					helpers.LogoutCF()
    84  					helpers.LoginAs(unprivilegedUsername, password)
    85  				})
    86  
    87  				AfterEach(func() {
    88  					helpers.LoginCF()
    89  					helpers.TargetOrgAndSpace(orgName, spaceName)
    90  					helpers.DeleteUser(unprivilegedUsername)
    91  				})
    92  
    93  				It("says that no service brokers were found", func() {
    94  					Eventually(session).Should(Say("Getting service brokers as"))
    95  					Eventually(session).Should(Say("No service brokers found"))
    96  					Eventually(session).Should(Exit(0))
    97  				})
    98  			})
    99  		})
   100  	})
   101  })