github.com/loafoe/cli@v7.1.0+incompatible/integration/v6/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/servicebrokerstub"
     7  
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     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("bind app to provided services from manifest", func() {
    16  	var (
    17  		appName                         string
    18  		managedServiceInstanceName      string
    19  		userProvidedServiceInstanceName string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		appName = helpers.NewAppName()
    24  		managedServiceInstanceName = helpers.PrefixedRandomName("si")
    25  		userProvidedServiceInstanceName = helpers.PrefixedRandomName("usi")
    26  	})
    27  
    28  	When("the services do not exist", func() {
    29  		It("fails with the service not found message", func() {
    30  			helpers.WithHelloWorldApp(func(dir string) {
    31  				helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    32  					"applications": []map[string]interface{}{
    33  						{
    34  							"name":     appName,
    35  							"path":     dir,
    36  							"services": []string{managedServiceInstanceName, userProvidedServiceInstanceName},
    37  						},
    38  					},
    39  				})
    40  
    41  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
    42  				Eventually(session.Err).Should(Say("Service instance %s not found", managedServiceInstanceName))
    43  				Eventually(session).Should(Say("FAILED"))
    44  				Eventually(session).Should(Exit(1))
    45  			})
    46  		})
    47  	})
    48  
    49  	When("the services do exist", func() {
    50  		var broker *servicebrokerstub.ServiceBrokerStub
    51  
    52  		BeforeEach(func() {
    53  			broker = servicebrokerstub.EnableServiceAccess()
    54  
    55  			Eventually(helpers.CF("create-service", broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), managedServiceInstanceName)).Should(Exit(0))
    56  
    57  			Eventually(helpers.CF("create-user-provided-service", userProvidedServiceInstanceName)).Should(Exit(0))
    58  		})
    59  
    60  		AfterEach(func() {
    61  			broker.Forget()
    62  		})
    63  
    64  		When("the app is new", func() {
    65  			It("binds the provided services", func() {
    66  				helpers.WithHelloWorldApp(func(dir string) {
    67  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    68  						"applications": []map[string]interface{}{
    69  							{
    70  								"name":     appName,
    71  								"path":     dir,
    72  								"services": []string{managedServiceInstanceName, userProvidedServiceInstanceName},
    73  							},
    74  						},
    75  					})
    76  
    77  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
    78  					Eventually(session).Should(Say(`Getting app info\.\.\.`))
    79  					Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`))
    80  					Eventually(session).Should(Say(`\+\s+name:\s+%s`, appName))
    81  					Eventually(session).Should(Say("services:"))
    82  					Eventually(session).Should(Say(`\+\s+%s`, managedServiceInstanceName))
    83  					Eventually(session).Should(Say(`\+\s+%s`, userProvidedServiceInstanceName))
    84  					Eventually(session).Should(Say(`Binding services\.\.\.`))
    85  					Eventually(session).Should(Exit(0))
    86  				})
    87  
    88  				session := helpers.CF("services")
    89  				Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation`))
    90  				Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s`, managedServiceInstanceName, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName))
    91  				Eventually(session).Should(Say(`%s\s+user-provided\s+%s`, userProvidedServiceInstanceName, appName))
    92  
    93  			})
    94  		})
    95  
    96  		When("the app already exists", func() {
    97  			BeforeEach(func() {
    98  				helpers.WithHelloWorldApp(func(dir string) {
    99  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   100  						"applications": []map[string]interface{}{
   101  							{
   102  								"name":     appName,
   103  								"path":     dir,
   104  								"services": []string{managedServiceInstanceName},
   105  							},
   106  						},
   107  					})
   108  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   109  					Eventually(session).Should(Exit(0))
   110  				})
   111  			})
   112  
   113  			It("binds the unbound services", func() {
   114  				helpers.WithHelloWorldApp(func(dir string) {
   115  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   116  						"applications": []map[string]interface{}{
   117  							{
   118  								"name":     appName,
   119  								"path":     dir,
   120  								"services": []string{managedServiceInstanceName, userProvidedServiceInstanceName},
   121  							},
   122  						},
   123  					})
   124  
   125  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   126  					Eventually(session).Should(Say(`Getting app info\.\.\.`))
   127  					Eventually(session).Should(Say(`Updating app with these attributes\.\.\.`))
   128  					Eventually(session).Should(Say(`\s+name:\s+%s`, appName))
   129  					Eventually(session).Should(Say("services:"))
   130  					Eventually(session).Should(Say(`(?m)$\s+%s`, managedServiceInstanceName))
   131  					Eventually(session).Should(Say(`\+\s+%s`, userProvidedServiceInstanceName))
   132  					Eventually(session).Should(Say(`Binding services\.\.\.`))
   133  					Eventually(session).Should(Exit(0))
   134  				})
   135  
   136  				session := helpers.CF("services")
   137  				Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation`))
   138  				Eventually(session).Should(Say(`%s\s+user-provided\s+%s`, userProvidedServiceInstanceName, appName))
   139  			})
   140  		})
   141  	})
   142  })