github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/enable_service_access_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("enable service access 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("enable-service-access", "--help")
    17  				Eventually(session).Should(Exit(0))
    18  				Expect(session).To(Say("NAME:"))
    19  				Expect(session).To(Say("\\s+enable-service-access - Enable access to a service offering or service plan for one or all orgs"))
    20  				Expect(session).To(Say("USAGE:"))
    21  				Expect(session).To(Say("\\s+cf enable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]"))
    22  				Expect(session).To(Say("OPTIONS:"))
    23  				Expect(session).To(Say("\\s+\\-b\\s+Enable access to a service offering from a particular service broker. Required when service offering name is ambiguous"))
    24  				Expect(session).To(Say("\\s+\\-o\\s+Enable access for a specified organization"))
    25  				Expect(session).To(Say("\\s+\\-p\\s+Enable access to a specified service plan"))
    26  				Expect(session).To(Say("SEE ALSO:"))
    27  				Expect(session).To(Say("\\s+disable-service-access, marketplace, service-access, service-brokers"))
    28  			})
    29  		})
    30  
    31  		When("no service argument was provided", func() {
    32  			It("displays a warning, the help text, and exits 1", func() {
    33  				session := helpers.CF("enable-service-access")
    34  				Eventually(session).Should(Exit(1))
    35  				Expect(session.Err).To(Say("Incorrect Usage: the required argument `SERVICE` was not provided"))
    36  				Expect(session).To(Say("NAME:"))
    37  				Expect(session).To(Say("\\s+enable-service-access - Enable access to a service offering or service plan for one or all orgs"))
    38  				Expect(session).To(Say("USAGE:"))
    39  				Expect(session).To(Say("\\s+cf enable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]"))
    40  				Expect(session).To(Say("OPTIONS:"))
    41  				Expect(session).To(Say("\\s+\\-b\\s+Enable access to a service offering from a particular service broker. Required when service offering name is ambiguous"))
    42  				Expect(session).To(Say("\\s+\\-o\\s+Enable access for a specified organization"))
    43  				Expect(session).To(Say("\\s+\\-p\\s+Enable access to a specified service plan"))
    44  				Expect(session).To(Say("SEE ALSO:"))
    45  				Expect(session).To(Say("\\s+disable-service-access, marketplace, service-access, service-brokers"))
    46  			})
    47  		})
    48  
    49  		When("two services arguments are provided", func() {
    50  			It("displays an error, and exits 1", func() {
    51  				session := helpers.CF("enable-service-access", "a-service", "another-service")
    52  				Eventually(session).Should(Exit(1))
    53  				Expect(session).To(Say("FAILED"))
    54  				Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "another-service"`))
    55  				Expect(session).To(Say("NAME:"))
    56  				Expect(session).To(Say("\\s+enable-service-access - Enable access to a service offering or service plan for one or all orgs"))
    57  				Expect(session).To(Say("USAGE:"))
    58  				Expect(session).To(Say("\\s+cf enable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]"))
    59  				Expect(session).To(Say("OPTIONS:"))
    60  				Expect(session).To(Say("\\s+\\-b\\s+Enable access to a service offering from a particular service broker. Required when service offering name is ambiguous"))
    61  				Expect(session).To(Say("\\s+\\-o\\s+Enable access for a specified organization"))
    62  				Expect(session).To(Say("\\s+\\-p\\s+Enable access to a specified service plan"))
    63  				Expect(session).To(Say("SEE ALSO:"))
    64  				Expect(session).To(Say("\\s+disable-service-access, marketplace, service-access, service-brokers"))
    65  			})
    66  		})
    67  	})
    68  
    69  	When("logged in", func() {
    70  		var username string
    71  		BeforeEach(func() {
    72  			username, _ = helpers.GetCredentials()
    73  			helpers.LoginCF()
    74  		})
    75  
    76  		Context("the service does not exist", func() {
    77  			It("displays FAILED, an informative error message, and exits 1", func() {
    78  				session := helpers.CF("enable-service-access", "some-service")
    79  				Eventually(session).Should(Exit(1))
    80  				Expect(session).To(Say("Enabling access to all plans of service offering some-service for all orgs as %s\\.\\.\\.", username))
    81  				Expect(session).To(Say("FAILED"))
    82  				Expect(session.Err).To(Say("Service offering 'some-service' not found"))
    83  			})
    84  		})
    85  
    86  		Context("service offerings exist", func() {
    87  			var (
    88  				orgName         string
    89  				spaceName       string
    90  				serviceOffering string
    91  				servicePlan     string
    92  				broker          *servicebrokerstub.ServiceBrokerStub
    93  				secondBroker    *servicebrokerstub.ServiceBrokerStub
    94  			)
    95  
    96  			BeforeEach(func() {
    97  				orgName = helpers.NewOrgName()
    98  				spaceName = helpers.NewSpaceName()
    99  				helpers.SetupCF(orgName, spaceName)
   100  
   101  				broker = servicebrokerstub.New().WithPlans(2).Create().Register()
   102  				serviceOffering = broker.FirstServiceOfferingName()
   103  				servicePlan = broker.FirstServicePlanName()
   104  
   105  				session := helpers.CF("service-access", "-e", serviceOffering, "-b", broker.Name)
   106  				Eventually(session).Should(Exit(0))
   107  				Expect(session).To(Say("%s\\s+%s\\s+none",
   108  					serviceOffering,
   109  					servicePlan,
   110  				))
   111  			})
   112  
   113  			AfterEach(func() {
   114  				helpers.QuickDeleteOrg(orgName)
   115  				broker.Forget()
   116  			})
   117  
   118  			When("service offering name provided", func() {
   119  				It("makes all the plans public", func() {
   120  					session := helpers.CF("enable-service-access", serviceOffering)
   121  					Eventually(session).Should(Exit(0))
   122  					Expect(session).To(Say("Enabling access to all plans of service offering %s for all orgs as %s...", serviceOffering, username))
   123  					Expect(session).To(Say("OK"))
   124  
   125  					session = helpers.CF("service-access", "-e", serviceOffering)
   126  					Eventually(session).Should(Exit(0))
   127  					Expect(session).To(Say("broker:\\s+%s", broker.Name))
   128  					Expect(session).To(Say("%s\\s+%s\\s+all",
   129  						serviceOffering,
   130  						servicePlan,
   131  					))
   132  				})
   133  			})
   134  
   135  			When("service offering name, plan name and org provided", func() {
   136  				It("makes the plan public", func() {
   137  					session := helpers.CF("enable-service-access", serviceOffering, "-p", servicePlan, "-o", orgName, "-v")
   138  					Eventually(session).Should(Exit(0))
   139  					Expect(session).To(Say("Enabling access to plan %s of service offering %s for org %s as %s...", servicePlan, serviceOffering, orgName, username))
   140  					Expect(session).To(Say("OK"))
   141  
   142  					session = helpers.CF("service-access", "-e", serviceOffering)
   143  					Eventually(session).Should(Exit(0))
   144  					Expect(session).To(Say("broker:\\s+%s", broker.Name))
   145  					Expect(session).To(Say("%s\\s+%s\\s+%s\\s+%s",
   146  						serviceOffering,
   147  						servicePlan,
   148  						"limited",
   149  						orgName,
   150  					))
   151  				})
   152  			})
   153  
   154  			When("two services with the same name are registered", func() {
   155  				BeforeEach(func() {
   156  					secondBroker = servicebrokerstub.New()
   157  					secondBroker.Services[0].Name = serviceOffering
   158  					secondBroker.Services[0].Plans[0].Name = servicePlan
   159  					secondBroker.Create().Register()
   160  				})
   161  
   162  				AfterEach(func() {
   163  					secondBroker.Forget()
   164  				})
   165  
   166  				When("a serviceOffering name and broker name are provided", func() {
   167  					It("displays an informative message, exits 0, and enables access to the serviceOffering", func() {
   168  						session := helpers.CF("enable-service-access", serviceOffering, "-b", secondBroker.Name)
   169  						Eventually(session).Should(Exit(0))
   170  						Expect(session).To(Say("Enabling access to all plans of service offering %s from broker %s for all orgs as %s...", serviceOffering, secondBroker.Name, username))
   171  						Expect(session).To(Say("OK"))
   172  
   173  						session = helpers.CF("service-access", "-b", secondBroker.Name)
   174  						Eventually(session).Should(Exit(0))
   175  						Expect(session).To(Say("broker:\\s+%s", secondBroker.Name))
   176  						Expect(session).To(Say("%s\\s+%s\\s+all",
   177  							serviceOffering,
   178  							servicePlan,
   179  						))
   180  					})
   181  				})
   182  			})
   183  
   184  			Context("when access is already globally enabled", func() {
   185  				BeforeEach(func() {
   186  					Eventually(helpers.CF("enable-service-access", serviceOffering)).Should(Exit(0))
   187  				})
   188  
   189  				When("when we try to enable access for an org", func() {
   190  					It("should still be enabled only globally", func() {
   191  						session := helpers.CF("enable-service-access", serviceOffering, "-o", orgName)
   192  						Eventually(session).Should(Exit(0))
   193  						Expect(session).To(Say("Did not update plan %s as it already has visibility all\\.", broker.Services[0].Plans[0].Name))
   194  						Expect(session).To(Say("Did not update plan %s as it already has visibility all\\.", broker.Services[0].Plans[1].Name))
   195  						Expect(session).To(Say("OK"))
   196  
   197  						session = helpers.CF("service-access", "-e", serviceOffering)
   198  						Eventually(session).Should(Exit(0))
   199  						Expect(session).To(Say("broker:\\s+%s", broker.Name))
   200  						Expect(session).To(Say("%s\\s+%s\\s+all",
   201  							serviceOffering,
   202  							servicePlan,
   203  						))
   204  						Expect(string(session.Out.Contents())).NotTo(ContainSubstring(orgName))
   205  					})
   206  				})
   207  
   208  				When("when we try to enable access for an org for a plan", func() {
   209  					It("should still be enabled only globally", func() {
   210  						session := helpers.CF("enable-service-access", serviceOffering, "-o", orgName, "-p", servicePlan)
   211  						Eventually(session).Should(Exit(0))
   212  						Expect(session).To(Say("Did not update plan %s as it already has visibility all\\.", servicePlan))
   213  						Expect(session).To(Say("OK"))
   214  
   215  						session = helpers.CF("service-access", "-e", serviceOffering)
   216  						Eventually(session).Should(Exit(0))
   217  						Expect(session).To(Say("broker:\\s+%s", broker.Name))
   218  						Expect(session).To(Say("%s\\s+%s\\s+all",
   219  							serviceOffering,
   220  							servicePlan,
   221  						))
   222  						Expect(string(session.Out.Contents())).NotTo(ContainSubstring(orgName))
   223  					})
   224  				})
   225  			})
   226  		})
   227  	})
   228  
   229  	Context("not logged in", func() {
   230  		BeforeEach(func() {
   231  			helpers.LogoutCF()
   232  		})
   233  
   234  		It("displays FAILED, an informative error message, and exits 1", func() {
   235  			session := helpers.CF("enable-service-access", "does-not-matter")
   236  			Eventually(session).Should(Exit(1))
   237  			Expect(session).To(Say("FAILED"))
   238  			Expect(session.Err).To(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in."))
   239  		})
   240  	})
   241  
   242  })