github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/isolated/enable_service_access_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gbytes"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = Describe("enable service access command", func() {
    12  	Describe("help", func() {
    13  		When("--help flag is set", func() {
    14  			It("displays command usage to output", func() {
    15  				session := helpers.CF("enable-service-access", "--help")
    16  				Eventually(session).Should(Say("NAME:"))
    17  				Eventually(session).Should(Say("\\s+enable-service-access - Enable access to a service or service plan for one or all orgs"))
    18  				Eventually(session).Should(Say("USAGE:"))
    19  				Eventually(session).Should(Say("\\s+cf enable-service-access SERVICE \\[-p PLAN\\] \\[-o ORG\\]"))
    20  				Eventually(session).Should(Say("OPTIONS:"))
    21  				Eventually(session).Should(Say("\\s+\\-o\\s+Enable access for a specified organization"))
    22  				Eventually(session).Should(Say("\\s+\\-p\\s+Enable access to a specified service plan"))
    23  				Eventually(session).Should(Say("SEE ALSO:"))
    24  				Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers"))
    25  				Eventually(session).Should(Exit(0))
    26  			})
    27  		})
    28  	})
    29  
    30  	When("no service argument was provided", func() {
    31  		It("displays a warning, the help text, and exits 1", func() {
    32  			session := helpers.CF("enable-service-access")
    33  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SERVICE` was not provided"))
    34  			Eventually(session).Should(Say("NAME:"))
    35  			Eventually(session).Should(Say("\\s+enable-service-access - Enable access to a service or service plan for one or all orgs"))
    36  			Eventually(session).Should(Say("USAGE:"))
    37  			Eventually(session).Should(Say("\\s+cf enable-service-access SERVICE \\[-p PLAN\\] \\[-o ORG\\]"))
    38  			Eventually(session).Should(Say("OPTIONS:"))
    39  			Eventually(session).Should(Say("\\s+\\-o\\s+Enable access for a specified organization"))
    40  			Eventually(session).Should(Say("\\s+\\-p\\s+Enable access to a specified service plan"))
    41  			Eventually(session).Should(Say("SEE ALSO:"))
    42  			Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers"))
    43  			Eventually(session).Should(Exit(1))
    44  		})
    45  	})
    46  
    47  	When("two services arguments are provided", func() {
    48  		It("displays an error, and exits 1", func() {
    49  			session := helpers.CF("enable-service-access", "a-service", "another-service")
    50  			Eventually(session).Should(Say("FAILED"))
    51  			Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "another-service"`))
    52  			Eventually(session).Should(Say("NAME:"))
    53  			Eventually(session).Should(Say("\\s+enable-service-access - Enable access to a service or service plan for one or all orgs"))
    54  			Eventually(session).Should(Say("USAGE:"))
    55  			Eventually(session).Should(Say("\\s+cf enable-service-access SERVICE \\[-p PLAN\\] \\[-o ORG\\]"))
    56  			Eventually(session).Should(Say("OPTIONS:"))
    57  			Eventually(session).Should(Say("\\s+\\-o\\s+Enable access for a specified organization"))
    58  			Eventually(session).Should(Say("\\s+\\-p\\s+Enable access to a specified service plan"))
    59  			Eventually(session).Should(Say("SEE ALSO:"))
    60  			Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers"))
    61  			Eventually(session).Should(Exit(1))
    62  		})
    63  	})
    64  
    65  	Context("not logged in", func() {
    66  		BeforeEach(func() {
    67  			helpers.LogoutCF()
    68  		})
    69  
    70  		It("displays FAILED, an informative error message, and exits 1", func() {
    71  			session := helpers.CF("enable-service-access", "does-not-matter")
    72  			Eventually(session).Should(Say("FAILED"))
    73  			Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in."))
    74  			Eventually(session).Should(Exit(1))
    75  		})
    76  	})
    77  
    78  	Context("logged in", func() {
    79  		BeforeEach(func() {
    80  			helpers.LoginCF()
    81  		})
    82  
    83  		Context("the service does not exist", func() {
    84  			When("only the service is specified", func() {
    85  				It("displays FAILED, an informative error message, and exits 1", func() {
    86  					session := helpers.CF("enable-service-access", "some-service")
    87  					Eventually(session).Should(Say("Enabling access to all plans of service some-service for all orgs as admin\\.\\.\\."))
    88  					Eventually(session).Should(Say("FAILED"))
    89  					Eventually(session.Err).Should(Say("Service offering 'some-service' not found"))
    90  					Eventually(session).Should(Exit(1))
    91  				})
    92  			})
    93  
    94  			When("a service and an org are specified", func() {
    95  				It("displays FAILED, an informative error message, and exits 1", func() {
    96  					session := helpers.CF("enable-service-access", "some-service", "-o", "some-org")
    97  					Eventually(session).Should(Say("Enabling access to all plans of service some-service for the org some-org as admin\\.\\.\\."))
    98  					Eventually(session).Should(Say("FAILED"))
    99  					Eventually(session.Err).Should(Say("Service offering 'some-service' not found"))
   100  					Eventually(session).Should(Exit(1))
   101  				})
   102  			})
   103  
   104  			When("a service and a plan are specified", func() {
   105  				It("displays FAILED, an informative error message, and exits 1", func() {
   106  					session := helpers.CF("enable-service-access", "some-service", "-p", "some-plan")
   107  					Eventually(session).Should(Say("Enabling access of plan some-plan for service some-service as admin\\.\\.\\."))
   108  					Eventually(session).Should(Say("FAILED"))
   109  					Eventually(session.Err).Should(Say("Service offering 'some-service' not found"))
   110  					Eventually(session).Should(Exit(1))
   111  				})
   112  			})
   113  
   114  			When("a service, a plan and an org are specified", func() {
   115  				It("displays FAILED, an informative error message, and exits 1", func() {
   116  					session := helpers.CF("enable-service-access", "some-service", "-p", "some-plan", "-o", "some-org")
   117  					Eventually(session).Should(Say("Enabling access to plan some-plan of service some-service for org some-org as admin\\.\\.\\."))
   118  					Eventually(session).Should(Say("FAILED"))
   119  					Eventually(session.Err).Should(Say("Service offering 'some-service' not found"))
   120  					Eventually(session).Should(Exit(1))
   121  				})
   122  			})
   123  		})
   124  
   125  		Context("a service broker is registered", func() {
   126  			var (
   127  				orgName     string
   128  				spaceName   string
   129  				domain      string
   130  				service     string
   131  				servicePlan string
   132  				broker      helpers.ServiceBroker
   133  			)
   134  
   135  			BeforeEach(func() {
   136  				orgName = helpers.NewOrgName()
   137  				spaceName = helpers.NewSpaceName()
   138  				helpers.SetupCF(orgName, spaceName)
   139  
   140  				domain = helpers.DefaultSharedDomain()
   141  				service = helpers.PrefixedRandomName("SERVICE")
   142  				servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN")
   143  
   144  				broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan)
   145  				broker.Push()
   146  				broker.Configure(true)
   147  				broker.Create()
   148  			})
   149  
   150  			AfterEach(func() {
   151  				broker.Destroy()
   152  				helpers.QuickDeleteOrg(orgName)
   153  			})
   154  
   155  			When("a service name is provided", func() {
   156  				It("displays an informative message, exits 0, and enables the service for all orgs", func() {
   157  					session := helpers.CF("enable-service-access", service)
   158  					Eventually(session).Should(Say("Enabling access to all plans of service %s for all orgs as admin...", service))
   159  					Eventually(session).Should(Say("OK"))
   160  					Eventually(session).Should(Exit(0))
   161  
   162  					session = helpers.CF("service-access", "-e", service)
   163  					Eventually(session).Should(Exit(0))
   164  					Eventually(session).Should(Say("broker:\\s+%s", broker.Name))
   165  					Eventually(session).Should(Say("%s\\s+%s\\s+all",
   166  						service,
   167  						servicePlan,
   168  					))
   169  				})
   170  
   171  				When("service is already enabled for an org", func() {
   172  					BeforeEach(func() {
   173  						session := helpers.CF("enable-service-access", service, "-p", servicePlan, "-o", orgName)
   174  						Eventually(session).Should(Say("OK"))
   175  						Eventually(session).Should(Exit(0))
   176  					})
   177  
   178  					It("disables the limited access for that org", func() {
   179  						session := helpers.CF("enable-service-access", service, "-p", servicePlan, "-v")
   180  						Eventually(session).Should(Say("Enabling access of plan %s for service %s as admin...", servicePlan, service))
   181  						Eventually(session).Should(Say("OK"))
   182  						Eventually(session).Should(Exit(0))
   183  
   184  						session = helpers.CF("service-access", "-e", service)
   185  						Eventually(session).Should(Exit(0))
   186  						Eventually(session).Should(Say("broker:\\s+%s", broker.Name))
   187  						Eventually(session).Should(Say("%s\\s+%s\\s+all\\s",
   188  							service,
   189  							servicePlan,
   190  						))
   191  
   192  					})
   193  				})
   194  			})
   195  
   196  			When("a service name and plan name are provided", func() {
   197  				It("displays an informative message, exits 0, and enables the plan for all orgs", func() {
   198  					session := helpers.CF("enable-service-access", service, "-p", servicePlan)
   199  					Eventually(session).Should(Say("Enabling access of plan %s for service %s as admin...", servicePlan, service))
   200  					Eventually(session).Should(Say("OK"))
   201  					Eventually(session).Should(Exit(0))
   202  
   203  					session = helpers.CF("service-access", "-e", service)
   204  					Eventually(session).Should(Exit(0))
   205  					Eventually(session).Should(Say("broker:\\s+%s", broker.Name))
   206  					Eventually(session).Should(Say("%s\\s+%s\\s+all",
   207  						service,
   208  						servicePlan,
   209  					))
   210  				})
   211  			})
   212  
   213  			When("a service name and org is provided", func() {
   214  				It("displays an informative message, and exits 0", func() {
   215  					session := helpers.CF("enable-service-access", service, "-o", orgName)
   216  					Eventually(session).Should(Say("Enabling access to all plans of service %s for the org %s as admin...", service, orgName))
   217  					Eventually(session).Should(Say("OK"))
   218  					Eventually(session).Should(Exit(0))
   219  				})
   220  			})
   221  
   222  			When("a service name, plan name and org is provided", func() {
   223  				It("displays an informative message, and exits 0", func() {
   224  					session := helpers.CF("enable-service-access", service, "-p", servicePlan, "-o", orgName)
   225  					Eventually(session).Should(Say("Enabling access to plan %s of service %s for org %s as admin...", servicePlan, service, orgName))
   226  					Eventually(session).Should(Say("OK"))
   227  					Eventually(session).Should(Exit(0))
   228  
   229  					session = helpers.CF("service-access", "-e", service)
   230  					Eventually(session).Should(Exit(0))
   231  					Eventually(session).Should(Say("broker:\\s+%s", broker.Name))
   232  					Eventually(session).Should(Say("%s\\s+%s\\s+%s\\s+%s",
   233  						service,
   234  						servicePlan,
   235  						"limited",
   236  						orgName,
   237  					))
   238  				})
   239  			})
   240  
   241  			When("the org does not exist", func() {
   242  				It("displays FAILED, an informative error message, and exits 1", func() {
   243  					session := helpers.CF("enable-service-access", service, "-o", "not-a-real-org")
   244  					Eventually(session).Should(Say("Enabling access to all plans of service %s for the org not-a-real-org as admin...", service))
   245  					Eventually(session).Should(Say("FAILED"))
   246  					Eventually(session.Err).Should(Say("Organization 'not-a-real-org' not found"))
   247  					Eventually(session).Should(Exit(1))
   248  				})
   249  			})
   250  
   251  			When("the plan does not exist", func() {
   252  				It("displays FAILED, an informative error message, and exits 1", func() {
   253  					session := helpers.CF("enable-service-access", service, "-p", "plan-does-not-exist")
   254  					Eventually(session).Should(Say("Enabling access of plan plan-does-not-exist for service %s as admin...", service))
   255  					Eventually(session).Should(Say("FAILED"))
   256  					Eventually(session.Err).Should(Say("The plan plan-does-not-exist could not be found for service %s", service))
   257  					Eventually(session).Should(Exit(1))
   258  				})
   259  			})
   260  
   261  			When("the plan does exist and the org does not exist", func() {
   262  				It("displays FAILED, an informative error message, and exits 1", func() {
   263  					session := helpers.CF("enable-service-access", service, "-p", servicePlan, "-o", "not-a-real-org")
   264  					Eventually(session).Should(Say("Enabling access to plan %s of service %s for org not-a-real-org as admin...", servicePlan, service))
   265  					Eventually(session).Should(Say("FAILED"))
   266  					Eventually(session.Err).Should(Say("Organization 'not-a-real-org' not found"))
   267  					Eventually(session).Should(Exit(1))
   268  				})
   269  			})
   270  
   271  			When("the plan does not exist and the org does exist", func() {
   272  				It("displays FAILED, an informative error message, and exits 1", func() {
   273  					session := helpers.CF("enable-service-access", service, "-p", "not-a-real-plan", "-o", orgName)
   274  					Eventually(session).Should(Say("Enabling access to plan not-a-real-plan of service %s for org %s as admin...", service, orgName))
   275  					Eventually(session).Should(Say("FAILED"))
   276  					Eventually(session.Err).Should(Say("Service plan 'not-a-real-plan' not found"))
   277  					Eventually(session).Should(Exit(1))
   278  				})
   279  			})
   280  
   281  			Context("when access is already enabled in the org", func() {
   282  				BeforeEach(func() {
   283  					session := helpers.CF("enable-service-access", service, "-o", orgName)
   284  					Eventually(session).Should(Say("OK"))
   285  				})
   286  
   287  				It("displays FAILED, an informative error message and exits 1", func() {
   288  					session := helpers.CF("enable-service-access", service, "-o", orgName)
   289  					Eventually(session).Should(Say("Enabling access to all plans of service %s for the org %s as admin...", service, orgName))
   290  					Eventually(session).Should(Say("FAILED"))
   291  					Eventually(session.Err).Should(Say("^This combination of ServicePlan and Organization is already taken: organization_id and service_plan_id unique"))
   292  					Eventually(session).Should(Exit(1))
   293  				})
   294  			})
   295  
   296  			Context("when access is already globally enabled", func() {
   297  				BeforeEach(func() {
   298  					helpers.CF("enable-service-access", service)
   299  				})
   300  
   301  				When("the service already has access globally enabled", func() {
   302  					It("displays an informative message, and exits 0", func() {
   303  						session := helpers.CF("enable-service-access", service)
   304  						Eventually(session).Should(Say("Enabling access to all plans of service %s for all orgs as admin...", service))
   305  						Eventually(session).Should(Say("OK"))
   306  						Eventually(session).Should(Exit(0))
   307  					})
   308  				})
   309  
   310  				When("the plan already has access globally enabled", func() {
   311  					It("displays an informative message, and exits 0", func() {
   312  						session := helpers.CF("enable-service-access", service, "-p", servicePlan)
   313  						Eventually(session).Should(Say("Enabling access of plan %s for service %s as admin...", servicePlan, service))
   314  						Eventually(session).Should(Say("OK"))
   315  						Eventually(session).Should(Exit(0))
   316  					})
   317  				})
   318  			})
   319  		})
   320  	})
   321  })