github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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" 7 "code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("bind app to provided services from manifest", func() { 15 var ( 16 appName string 17 managedServiceInstanceName string 18 userProvidedServiceInstanceName string 19 ) 20 21 BeforeEach(func() { 22 appName = helpers.NewAppName() 23 managedServiceInstanceName = helpers.PrefixedRandomName("si") 24 userProvidedServiceInstanceName = helpers.PrefixedRandomName("usi") 25 }) 26 27 When("the services do not exist", func() { 28 It("fails with the service not found message", func() { 29 helpers.WithHelloWorldApp(func(dir string) { 30 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 31 "applications": []map[string]interface{}{ 32 { 33 "name": appName, 34 "path": dir, 35 "services": []string{managedServiceInstanceName, userProvidedServiceInstanceName}, 36 }, 37 }, 38 }) 39 40 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName) 41 Eventually(session.Err).Should(Say("Service instance %s not found", managedServiceInstanceName)) 42 Eventually(session).Should(Say("FAILED")) 43 Eventually(session).Should(Exit(1)) 44 }) 45 }) 46 }) 47 48 When("the services do exist", func() { 49 var broker *fakeservicebroker.FakeServiceBroker 50 51 BeforeEach(func() { 52 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 53 Eventually(helpers.CF("enable-service-access", broker.ServiceName())).Should(Exit(0)) 54 55 Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), managedServiceInstanceName)).Should(Exit(0)) 56 57 Eventually(helpers.CF("create-user-provided-service", userProvidedServiceInstanceName)).Should(Exit(0)) 58 }) 59 60 AfterEach(func() { 61 broker.Destroy() 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.ServiceName(), broker.ServicePlanName(), 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 })