github.com/arunkumar7540/cli@v6.45.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" 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 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 When("the services do exist", func() { 52 var broker helpers.ServiceBroker 53 54 BeforeEach(func() { 55 domain := helpers.DefaultSharedDomain() 56 57 broker = helpers.CreateBroker(domain, serviceName, servicePlan) 58 59 Eventually(helpers.CF("enable-service-access", serviceName)).Should(Exit(0)) 60 61 Eventually(helpers.CF("create-service", serviceName, servicePlan, managedServiceInstanceName)).Should(Exit(0)) 62 63 Eventually(helpers.CF("create-user-provided-service", userProvidedServiceInstanceName)).Should(Exit(0)) 64 }) 65 66 AfterEach(func() { 67 broker.Destroy() 68 }) 69 70 When("the app is new", func() { 71 It("binds the provided services", func() { 72 helpers.WithHelloWorldApp(func(dir string) { 73 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 74 "applications": []map[string]interface{}{ 75 { 76 "name": appName, 77 "path": dir, 78 "services": []string{managedServiceInstanceName, userProvidedServiceInstanceName}, 79 }, 80 }, 81 }) 82 83 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName) 84 Eventually(session).Should(Say(`Getting app info\.\.\.`)) 85 Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`)) 86 Eventually(session).Should(Say(`\+\s+name:\s+%s`, appName)) 87 Eventually(session).Should(Say("services:")) 88 Eventually(session).Should(Say(`\+\s+%s`, managedServiceInstanceName)) 89 Eventually(session).Should(Say(`\+\s+%s`, userProvidedServiceInstanceName)) 90 Eventually(session).Should(Say(`Binding services\.\.\.`)) 91 Eventually(session).Should(Exit(0)) 92 }) 93 94 session := helpers.CF("services") 95 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation`)) 96 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s`, managedServiceInstanceName, serviceName, servicePlan, appName)) 97 Eventually(session).Should(Say(`%s\s+user-provided\s+%s`, userProvidedServiceInstanceName, appName)) 98 99 }) 100 }) 101 102 When("the app already exists", func() { 103 BeforeEach(func() { 104 helpers.WithHelloWorldApp(func(dir string) { 105 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 106 "applications": []map[string]interface{}{ 107 { 108 "name": appName, 109 "path": dir, 110 "services": []string{managedServiceInstanceName}, 111 }, 112 }, 113 }) 114 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName) 115 Eventually(session).Should(Exit(0)) 116 }) 117 }) 118 119 It("binds the unbound services", func() { 120 helpers.WithHelloWorldApp(func(dir string) { 121 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 122 "applications": []map[string]interface{}{ 123 { 124 "name": appName, 125 "path": dir, 126 "services": []string{managedServiceInstanceName, userProvidedServiceInstanceName}, 127 }, 128 }, 129 }) 130 131 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName) 132 Eventually(session).Should(Say(`Getting app info\.\.\.`)) 133 Eventually(session).Should(Say(`Updating app with these attributes\.\.\.`)) 134 Eventually(session).Should(Say(`\s+name:\s+%s`, appName)) 135 Eventually(session).Should(Say("services:")) 136 Eventually(session).Should(Say(`(?m)$\s+%s`, managedServiceInstanceName)) 137 Eventually(session).Should(Say(`\+\s+%s`, userProvidedServiceInstanceName)) 138 Eventually(session).Should(Say(`Binding services\.\.\.`)) 139 Eventually(session).Should(Exit(0)) 140 }) 141 142 session := helpers.CF("services") 143 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation`)) 144 Eventually(session).Should(Say(`%s\s+user-provided\s+%s`, userProvidedServiceInstanceName, appName)) 145 }) 146 }) 147 }) 148 })