github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/shared/isolated/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/fakeservicebroker"
     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-access command", func() {
    13  	var (
    14  		userName string
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		userName, _ = helpers.GetCredentials()
    19  	})
    20  
    21  	Describe("help", func() {
    22  		When("--help flag is set", func() {
    23  			It("displays command usage to output", func() {
    24  				session := helpers.CF("service-access", "--help")
    25  				Eventually(session).Should(Say(`NAME:`))
    26  				Eventually(session).Should(Say(`\s+service-access - List service access settings`))
    27  				Eventually(session).Should(Say(`USAGE:`))
    28  				Eventually(session).Should(Say(`\s+cf service-access \[-b BROKER\] \[-e SERVICE\] \[-o ORG\]`))
    29  				Eventually(session).Should(Say(`OPTIONS:`))
    30  				Eventually(session).Should(Say(`\s+-b\s+Access for plans of a particular broker`))
    31  				Eventually(session).Should(Say(`\s+-e\s+Access for service name of a particular service offering`))
    32  				Eventually(session).Should(Say(`\s+-o\s+Plans accessible by a particular organization`))
    33  				Eventually(session).Should(Say(`SEE ALSO:`))
    34  				Eventually(session).Should(Say(`\s+disable-service-access, enable-service-access, marketplace, service-brokers`))
    35  				Eventually(session).Should(Exit(0))
    36  			})
    37  		})
    38  	})
    39  
    40  	When("the environment is not setup correctly", func() {
    41  		It("fails with the appropriate errors", func() {
    42  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "service-access")
    43  		})
    44  	})
    45  
    46  	When("the environment is setup correctly", func() {
    47  		BeforeEach(func() {
    48  			helpers.LoginCF()
    49  			helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace)
    50  		})
    51  
    52  		When("-b is provided with a broker name that does not exist", func() {
    53  			It("shows an error message", func() {
    54  				session := helpers.CF("service-access", "-b", "non-existent-broker")
    55  				Eventually(session).Should(Say(`Getting service access for broker non-existent-broker as %s\.\.\.`, userName))
    56  				Eventually(session.Err).Should(Say(`Service broker 'non-existent-broker' not found\.`))
    57  				Eventually(session.Err).Should(Say(`TIP: Use 'cf service-brokers' to see a list of available brokers\.`))
    58  				Eventually(session).Should(Exit(1))
    59  			})
    60  		})
    61  
    62  		When("-e is provided with a service name that does not exist", func() {
    63  			It("shows an error message", func() {
    64  				session := helpers.CF("service-access", "-e", "non-existent-service")
    65  				Eventually(session).Should(Say(`Getting service access for service non-existent-service as %s\.\.\.`, userName))
    66  				Eventually(session.Err).Should(Say(`Service offering 'non-existent-service' not found\.`))
    67  				Eventually(session).Should(Exit(1))
    68  			})
    69  		})
    70  
    71  		When("-o is provided with a org name that does not exist", func() {
    72  			It("shows an error message", func() {
    73  				session := helpers.CF("service-access", "-o", "non-existent-org")
    74  				Eventually(session).Should(Say(`Getting service access for organization non-existent-org as %s\.\.\.`, userName))
    75  				Eventually(session.Err).Should(Say(`Organization 'non-existent-org' not found`))
    76  				Eventually(session).Should(Exit(1))
    77  			})
    78  		})
    79  
    80  		When("there are service offerings", func() {
    81  			var (
    82  				orgName   string
    83  				spaceName string
    84  
    85  				service     string
    86  				servicePlan string
    87  				broker      *fakeservicebroker.FakeServiceBroker
    88  			)
    89  
    90  			BeforeEach(func() {
    91  				orgName = helpers.NewOrgName()
    92  				spaceName = helpers.NewSpaceName()
    93  				helpers.SetupCF(orgName, spaceName)
    94  
    95  				broker = fakeservicebroker.New()
    96  				broker.Services[0].Plans[1].Name = helpers.GenerateHigherName(helpers.NewPlanName, broker.Services[0].Plans[0].Name)
    97  				broker.EnsureBrokerIsAvailable()
    98  				service = broker.ServiceName()
    99  				servicePlan = broker.ServicePlanName()
   100  			})
   101  
   102  			AfterEach(func() {
   103  				broker.Destroy()
   104  				helpers.QuickDeleteOrg(orgName)
   105  			})
   106  
   107  			It("displays all service access information", func() {
   108  				By("showing 'none' when service access is disabled")
   109  				session := helpers.CF("service-access")
   110  				Eventually(session).Should(Say("Getting service access as %s...", userName))
   111  				Eventually(session).Should(Say(`service\s+plan\s+access\s+org`))
   112  				Eventually(session).Should(Say(`%s\s+%s\s+%s`, service, servicePlan, "none"))
   113  				Eventually(session).Should(Exit(0))
   114  
   115  				By("showing 'all' when service access is enabled globally")
   116  				Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
   117  				session = helpers.CF("service-access")
   118  				Eventually(session).Should(Say("Getting service access as %s...", userName))
   119  				Eventually(session).Should(Say(`service\s+plan\s+access\s+org`))
   120  				Eventually(session).Should(Say(`%s\s+%s\s+%s`, service, servicePlan, "all"))
   121  				Eventually(session).Should(Exit(0))
   122  			})
   123  
   124  			When("some services are only accessible to certain organizations", func() {
   125  				BeforeEach(func() {
   126  					Eventually(helpers.CF("enable-service-access", service, "-o", orgName)).Should(Exit(0))
   127  				})
   128  
   129  				It("shows 'limited' access to the service", func() {
   130  					session := helpers.CF("service-access")
   131  					Eventually(session).Should(Say("Getting service access as %s...", userName))
   132  					Eventually(session).Should(Say(`service\s+plan\s+access\s+org`))
   133  					Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s`, service, servicePlan, "limited", orgName))
   134  					Eventually(session).Should(Exit(0))
   135  				})
   136  			})
   137  
   138  			When("multiple brokers are registered and with varying service accessibility", func() {
   139  				var (
   140  					otherBroker *fakeservicebroker.FakeServiceBroker
   141  
   142  					otherOrgName string
   143  				)
   144  
   145  				BeforeEach(func() {
   146  					helpers.SetupCF(orgName, spaceName)
   147  
   148  					otherBroker = fakeservicebroker.NewAlternate()
   149  					otherBroker.Services[0].Plans[1].Name = helpers.GenerateLowerName(helpers.NewPlanName, otherBroker.Services[0].Plans[0].Name)
   150  					otherBroker.EnsureBrokerIsAvailable()
   151  
   152  					otherOrgName = helpers.GenerateLowerName(helpers.NewOrgName, orgName)
   153  					helpers.CreateOrg(otherOrgName)
   154  
   155  					Eventually(
   156  						helpers.CF("enable-service-access",
   157  							service,
   158  							"-o", otherOrgName,
   159  							"-p", servicePlan)).Should(Exit(0))
   160  					Eventually(helpers.CF("enable-service-access", otherBroker.Services[0].Name)).Should(Exit(0))
   161  				})
   162  
   163  				AfterEach(func() {
   164  					helpers.QuickDeleteOrg(otherOrgName)
   165  					otherBroker.Destroy()
   166  				})
   167  
   168  				When("the -b flag is passed", func() {
   169  					It("shows only services from the specified broker", func() {
   170  						session := helpers.CF("service-access", "-b", otherBroker.Name())
   171  						Eventually(session).Should(Say("Getting service access for broker %s as %s...", otherBroker.Name(), userName))
   172  						Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name()))
   173  						Eventually(session).Should(Say(`service\s+plan\s+access\s+org`))
   174  						Eventually(session).Should(Say(`%s\s+%s\s+%s`, otherBroker.Services[0].Name, otherBroker.Services[0].Plans[0].Name, "all"))
   175  						Eventually(string(session.Out.Contents())).ShouldNot(ContainSubstring(service))
   176  						Eventually(session).Should(Exit(0))
   177  					})
   178  				})
   179  
   180  				When("the -e flag is passed", func() {
   181  					It("shows only services from the specified service", func() {
   182  						session := helpers.CF("service-access", "-e", otherBroker.Services[0].Name)
   183  						Eventually(session).Should(Say("Getting service access for service %s as %s...", otherBroker.Services[0].Name, userName))
   184  						Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name()))
   185  						Eventually(session).Should(Say(`service\s+plan\s+access\s+org`))
   186  						Eventually(session).Should(Say(`%s\s+%s\s+%s`, otherBroker.Services[0].Name, otherBroker.Services[0].Plans[0].Name, "all"))
   187  						Eventually(string(session.Out.Contents())).ShouldNot(ContainSubstring(service))
   188  						Eventually(session).Should(Exit(0))
   189  					})
   190  				})
   191  
   192  				When("the -o flag is passed", func() {
   193  					It("displays only plans accessible by the specified organization", func() {
   194  						By("not displaying brokers that were only enabled in a different org than the provided one")
   195  						session := helpers.CF("service-access", "-o", orgName)
   196  						Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name()))
   197  						Eventually(session).Should(Say(`%s\s+%s\s+all`,
   198  							otherBroker.Services[0].Name,
   199  							otherBroker.Services[0].Plans[1].Name,
   200  						))
   201  						Eventually(session).Should(Say(`%s\s+%s\s+all`,
   202  							otherBroker.Services[0].Name,
   203  							otherBroker.Services[0].Plans[0].Name,
   204  						))
   205  						Consistently(session).ShouldNot(Say(`broker:\s+%s`, broker.Name()))
   206  						Eventually(session).Should(Exit(0))
   207  
   208  						By("displaying brokers that were enabled in the provided org")
   209  						session = helpers.CF("service-access", "-o", otherOrgName)
   210  						Eventually(session).Should(Say(`broker:\s+%s`, broker.Name()))
   211  						Eventually(session).Should(Say(`%s\s+%s\s+limited\s+%s`,
   212  							broker.Services[0].Name,
   213  							broker.Services[0].Plans[0].Name,
   214  							otherOrgName,
   215  						))
   216  						Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name()))
   217  						Eventually(session).Should(Say(`%s\s+%s\s+all`,
   218  							otherBroker.Services[0].Name,
   219  							otherBroker.Services[0].Plans[1].Name,
   220  						))
   221  						Eventually(session).Should(Say(`%s\s+%s\s+all`,
   222  							otherBroker.Services[0].Name,
   223  							otherBroker.Services[0].Plans[0].Name,
   224  						))
   225  
   226  						Eventually(session).Should(Exit(0))
   227  					})
   228  				})
   229  			})
   230  		})
   231  	})
   232  })