github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/push/bind_to_services_in_manifest_test.go (about)

     1  package push
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gbytes"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("bind app to provided services from manifest", func() {
    14  	var (
    15  		appName                         string
    16  		serviceName                     string
    17  		servicePlan                     string
    18  		managedServiceInstanceName      string
    19  		userProvidedServiceInstanceName string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		appName = helpers.NewAppName()
    24  		serviceName = helpers.PrefixedRandomName("SERVICE")
    25  		servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN")
    26  		managedServiceInstanceName = helpers.PrefixedRandomName("si")
    27  		userProvidedServiceInstanceName = helpers.PrefixedRandomName("usi")
    28  	})
    29  
    30  	Context("when the services do not exist", func() {
    31  		It("fails with the service not found message", func() {
    32  			helpers.WithHelloWorldApp(func(dir string) {
    33  				helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    34  					"applications": []map[string]interface{}{
    35  						{
    36  							"name":     appName,
    37  							"path":     dir,
    38  							"services": []string{managedServiceInstanceName, userProvidedServiceInstanceName},
    39  						},
    40  					},
    41  				})
    42  
    43  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
    44  				Eventually(session.Err).Should(Say("Service instance %s not found", managedServiceInstanceName))
    45  				Eventually(session).Should(Say("FAILED"))
    46  				Eventually(session).Should(Exit(1))
    47  			})
    48  		})
    49  	})
    50  
    51  	Context("when the services do exist", func() {
    52  		var broker helpers.ServiceBroker
    53  
    54  		BeforeEach(func() {
    55  			domain := defaultSharedDomain()
    56  
    57  			broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, serviceName, servicePlan)
    58  			broker.Push()
    59  			broker.Configure()
    60  			broker.Create()
    61  
    62  			Eventually(helpers.CF("enable-service-access", serviceName)).Should(Exit(0))
    63  
    64  			Eventually(helpers.CF("create-service", serviceName, servicePlan, managedServiceInstanceName)).Should(Exit(0))
    65  
    66  			Eventually(helpers.CF("create-user-provided-service", userProvidedServiceInstanceName)).Should(Exit(0))
    67  		})
    68  
    69  		AfterEach(func() {
    70  			broker.Destroy()
    71  		})
    72  
    73  		Context("when the app is new", func() {
    74  			It("binds the provided services", func() {
    75  				helpers.WithHelloWorldApp(func(dir string) {
    76  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    77  						"applications": []map[string]interface{}{
    78  							{
    79  								"name":     appName,
    80  								"path":     dir,
    81  								"services": []string{managedServiceInstanceName, userProvidedServiceInstanceName},
    82  							},
    83  						},
    84  					})
    85  
    86  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
    87  					Eventually(session).Should(Say("Getting app info\\.\\.\\."))
    88  					Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\."))
    89  					Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
    90  					Eventually(session).Should(Say("services:"))
    91  					Eventually(session).Should(Say("\\+\\s+%s", managedServiceInstanceName))
    92  					Eventually(session).Should(Say("\\+\\s+%s", userProvidedServiceInstanceName))
    93  					Eventually(session).Should(Say("Binding services\\.\\.\\."))
    94  					Eventually(session).Should(Exit(0))
    95  				})
    96  
    97  				session := helpers.CF("services")
    98  				Eventually(session).Should(Say("name\\s+service\\s+plan\\s+bound apps\\s+last operation"))
    99  				Eventually(session).Should(Say("%s\\s+%s\\s+%s\\s+%s", managedServiceInstanceName, serviceName, servicePlan, appName))
   100  				Eventually(session).Should(Say("%s\\s+user-provided\\s+%s", userProvidedServiceInstanceName, appName))
   101  
   102  			})
   103  		})
   104  
   105  		Context("when the app already exists", func() {
   106  			BeforeEach(func() {
   107  				helpers.WithHelloWorldApp(func(dir string) {
   108  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   109  						"applications": []map[string]interface{}{
   110  							{
   111  								"name":     appName,
   112  								"path":     dir,
   113  								"services": []string{managedServiceInstanceName},
   114  							},
   115  						},
   116  					})
   117  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   118  					Eventually(session).Should(Exit(0))
   119  				})
   120  			})
   121  
   122  			It("binds the unbound services", func() {
   123  				helpers.WithHelloWorldApp(func(dir string) {
   124  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   125  						"applications": []map[string]interface{}{
   126  							{
   127  								"name":     appName,
   128  								"path":     dir,
   129  								"services": []string{managedServiceInstanceName, userProvidedServiceInstanceName},
   130  							},
   131  						},
   132  					})
   133  
   134  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   135  					Eventually(session).Should(Say("Getting app info\\.\\.\\."))
   136  					Eventually(session).Should(Say("Updating app with these attributes\\.\\.\\."))
   137  					Eventually(session).Should(Say("\\s+name:\\s+%s", appName))
   138  					Eventually(session).Should(Say("services:"))
   139  					Eventually(session).Should(Say("(?m)$\\s+%s", managedServiceInstanceName))
   140  					Eventually(session).Should(Say("\\+\\s+%s", userProvidedServiceInstanceName))
   141  					Eventually(session).Should(Say("Binding services\\.\\.\\."))
   142  					Eventually(session).Should(Exit(0))
   143  				})
   144  
   145  				session := helpers.CF("services")
   146  				Eventually(session).Should(Say("name\\s+service\\s+plan\\s+bound apps\\s+last operation"))
   147  				Eventually(session).Should(Say("%s\\s+user-provided\\s+%s", userProvidedServiceInstanceName, appName))
   148  			})
   149  		})
   150  	})
   151  })