github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/integration/v7/isolated/create_service_broker_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"io"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub"
     7  
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     9  	"code.cloudfoundry.org/cli/integration/helpers"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("create-service-broker command", func() {
    17  	var brokerName string
    18  
    19  	BeforeEach(func() {
    20  		helpers.SkipIfV7AndVersionLessThan(ccversion.MinVersionCreateServiceBrokerV3)
    21  
    22  		brokerName = helpers.NewServiceBrokerName()
    23  
    24  		helpers.LoginCF()
    25  	})
    26  
    27  	Describe("help", func() {
    28  		When("--help flag is set", func() {
    29  			It("displays command usage to output", func() {
    30  				session := helpers.CF("create-service-broker", "--help")
    31  				Eventually(session).Should(Say("NAME:"))
    32  				Eventually(session).Should(Say("\\s+create-service-broker - Create a service broker"))
    33  
    34  				Eventually(session).Should(Say("USAGE:"))
    35  				Eventually(session).Should(Say("\\s+cf create-service-broker SERVICE_BROKER USERNAME PASSWORD URL \\[--space-scoped\\]"))
    36  
    37  				Eventually(session).Should(Say("ALIAS:"))
    38  				Eventually(session).Should(Say("\\s+csb"))
    39  
    40  				Eventually(session).Should(Say("OPTIONS:"))
    41  				Eventually(session).Should(Say("\\s+--space-scoped      Make the broker's service plans only visible within the targeted space"))
    42  
    43  				Eventually(session).Should(Say("SEE ALSO:"))
    44  				Eventually(session).Should(Say("\\s+enable-service-access, service-brokers, target"))
    45  
    46  				Eventually(session).Should(Exit(0))
    47  			})
    48  		})
    49  	})
    50  
    51  	When("not logged in", func() {
    52  		BeforeEach(func() {
    53  			helpers.LogoutCF()
    54  		})
    55  
    56  		It("displays an informative error that the user must be logged in", func() {
    57  			session := helpers.CF("create-service-broker", brokerName, "user", "pass", "http://example.com")
    58  			Eventually(session).Should(Say("FAILED"))
    59  			Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in."))
    60  			Eventually(session).Should(Exit(1))
    61  		})
    62  	})
    63  
    64  	When("logged in", func() {
    65  		When("all arguments are provided", func() {
    66  			When("no org or space is targeted", func() {
    67  				var (
    68  					username  string
    69  					orgName   string
    70  					spaceName string
    71  					broker    *servicebrokerstub.ServiceBrokerStub
    72  				)
    73  
    74  				BeforeEach(func() {
    75  					username, _ = helpers.GetCredentials()
    76  					orgName = helpers.NewOrgName()
    77  					spaceName = helpers.NewSpaceName()
    78  					helpers.SetupCF(orgName, spaceName)
    79  					broker = servicebrokerstub.Create()
    80  					helpers.ClearTarget()
    81  				})
    82  
    83  				AfterEach(func() {
    84  					Eventually(helpers.CF("delete-service-broker", brokerName, "-f")).Should(Exit(0))
    85  					helpers.QuickDeleteOrg(orgName)
    86  					broker.Forget()
    87  				})
    88  
    89  				It("registers the broker and service offerings and plans are available", func() {
    90  					session := helpers.CF("create-service-broker", brokerName, broker.Username, broker.Password, broker.URL)
    91  					Eventually(session).Should(Say("Creating service broker %s as %s...", brokerName, username))
    92  					Eventually(session).Should(Say("OK"))
    93  					Eventually(session).Should(Exit(0))
    94  
    95  					session = helpers.CF("service-access", "-b", brokerName)
    96  					Eventually(session).Should(Say(broker.FirstServiceOfferingName()))
    97  					Eventually(session).Should(Say(broker.FirstServicePlanName()))
    98  
    99  					session = helpers.CF("service-brokers")
   100  					Eventually(session).Should(Say(brokerName))
   101  				})
   102  			})
   103  
   104  			When("the --space-scoped flag is passed", func() {
   105  				BeforeEach(func() {
   106  					helpers.SkipIfV7AndVersionLessThan(ccversion.MinVersionCreateSpaceScopedServiceBrokerV3)
   107  				})
   108  
   109  				When("no org or space is targeted", func() {
   110  					BeforeEach(func() {
   111  						helpers.ClearTarget()
   112  					})
   113  
   114  					It("displays an informative error that a space must be targeted", func() {
   115  						session := helpers.CF("create-service-broker", "space-scoped-broker", "username", "password", "http://example.com", "--space-scoped")
   116  						Eventually(session).Should(Say("FAILED"))
   117  						Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org."))
   118  						Eventually(session).Should(Exit(1))
   119  					})
   120  				})
   121  
   122  				When("both org and space are targeted", func() {
   123  					var (
   124  						username  string
   125  						orgName   string
   126  						spaceName string
   127  						broker    *servicebrokerstub.ServiceBrokerStub
   128  					)
   129  
   130  					BeforeEach(func() {
   131  						username, _ = helpers.GetCredentials()
   132  						orgName = helpers.NewOrgName()
   133  						spaceName = helpers.NewSpaceName()
   134  						helpers.SetupCF(orgName, spaceName)
   135  						broker = servicebrokerstub.Create()
   136  					})
   137  
   138  					AfterEach(func() {
   139  						Eventually(helpers.CF("delete-service-broker", brokerName, "-f")).Should(Exit(0))
   140  						helpers.QuickDeleteOrg(orgName)
   141  						broker.Forget()
   142  					})
   143  
   144  					It("registers the broker and exposes its services only to the targeted space", func() {
   145  						session := helpers.CF("create-service-broker", brokerName, broker.Username, broker.Password, broker.URL, "--space-scoped")
   146  						Eventually(session).Should(Say(
   147  							"Creating service broker %s in org %s / space %s as %s...", brokerName, orgName, spaceName, username))
   148  						Eventually(session).Should(Say("OK"))
   149  						Eventually(session).Should(Exit(0))
   150  
   151  						session = helpers.CF("service-brokers")
   152  						Eventually(session).Should(Say(brokerName))
   153  
   154  						Eventually(func() io.Reader {
   155  							session := helpers.CF("marketplace")
   156  							Eventually(session).Should(Exit(0))
   157  
   158  							return session.Out
   159  						}).Should(Say(broker.FirstServicePlanName()))
   160  
   161  						helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace)
   162  						session = helpers.CF("marketplace")
   163  						Eventually(session).ShouldNot(Say(broker.FirstServicePlanName()))
   164  					})
   165  				})
   166  			})
   167  		})
   168  	})
   169  
   170  	When("the broker URL is invalid", func() {
   171  		BeforeEach(func() {
   172  			// TODO: replace skip with versioned skip when
   173  			// https://www.pivotaltracker.com/story/show/166215494 is resolved.
   174  			helpers.SkipIfV7()
   175  		})
   176  
   177  		It("displays a relevant error", func() {
   178  			session := helpers.CF("create-service-broker", brokerName, "user", "pass", "not-a-valid-url")
   179  			Eventually(session).Should(Say("FAILED"))
   180  			Eventually(session.Err).Should(Say("not-a-valid-url is not a valid URL"))
   181  			Eventually(session).Should(Exit(1))
   182  		})
   183  	})
   184  
   185  	When("no arguments are provided", func() {
   186  		It("displays an error, naming each of the missing args and the help text", func() {
   187  			session := helpers.CF("create-service-broker")
   188  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SERVICE_BROKER`, `USERNAME`, `PASSWORD` and `URL` were not provided"))
   189  
   190  			Eventually(session).Should(Say("NAME:"))
   191  			Eventually(session).Should(Say("\\s+create-service-broker - Create a service broker"))
   192  
   193  			Eventually(session).Should(Say("USAGE:"))
   194  			Eventually(session).Should(Say("\\s+cf create-service-broker SERVICE_BROKER USERNAME PASSWORD URL \\[--space-scoped\\]"))
   195  
   196  			Eventually(session).Should(Say("ALIAS:"))
   197  			Eventually(session).Should(Say("\\s+csb"))
   198  
   199  			Eventually(session).Should(Say("OPTIONS:"))
   200  			Eventually(session).Should(Say("\\s+--space-scoped      Make the broker's service plans only visible within the targeted space"))
   201  
   202  			Eventually(session).Should(Say("SEE ALSO:"))
   203  			Eventually(session).Should(Say("\\s+enable-service-access, service-brokers, target"))
   204  
   205  			Eventually(session).Should(Exit(1))
   206  		})
   207  	})
   208  })