github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/shared/isolated/create_service_broker_command_test.go (about)

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