github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/delete_orphaned_routes_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 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("delete-orphaned-routes command", func() { 14 Context("when the environment is not setup correctly", func() { 15 It("fails with the appropriate errors", func() { 16 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "delete-orphaned-routes") 17 }) 18 }) 19 20 Context("when the environment is setup correctly", func() { 21 var ( 22 orgName string 23 spaceName string 24 domainName string 25 appName string 26 domain helpers.Domain 27 ) 28 29 BeforeEach(func() { 30 orgName = helpers.NewOrgName() 31 spaceName = helpers.NewSpaceName() 32 domainName = helpers.DomainName() 33 appName = helpers.PrefixedRandomName("APP") 34 35 helpers.SetupCF(orgName, spaceName) 36 domain = helpers.NewDomain(orgName, domainName) 37 domain.Create() 38 }) 39 40 AfterEach(func() { 41 helpers.QuickDeleteOrg(orgName) 42 }) 43 44 Context("when there are orphaned routes", func() { 45 var ( 46 orphanedRoute1 helpers.Route 47 orphanedRoute2 helpers.Route 48 ) 49 50 BeforeEach(func() { 51 orphanedRoute1 = helpers.NewRoute(spaceName, domainName, "orphan-1", "path-1") 52 orphanedRoute2 = helpers.NewRoute(spaceName, domainName, "orphan-2", "path-2") 53 orphanedRoute1.Create() 54 orphanedRoute2.Create() 55 }) 56 57 It("deletes all the orphaned routes", func() { 58 Eventually(helpers.CF("delete-orphaned-routes", "-f")).Should(SatisfyAll( 59 Exit(0), 60 Say("Getting routes as"), 61 Say(fmt.Sprintf("Deleting route orphan-1.%s/path-1...", domainName)), 62 Say(fmt.Sprintf("Deleting route orphan-2.%s/path-2...", domainName)), 63 Say("OK"), 64 )) 65 }) 66 }) 67 68 Context("when there are orphaned routes and bound routes", func() { 69 var ( 70 orphanedRoute1 helpers.Route 71 orphanedRoute2 helpers.Route 72 boundRoute helpers.Route 73 ) 74 75 BeforeEach(func() { 76 orphanedRoute1 = helpers.NewRoute(spaceName, domainName, "orphan-1", "path-1") 77 orphanedRoute2 = helpers.NewRoute(spaceName, domainName, "orphan-2", "path-2") 78 orphanedRoute1.Create() 79 orphanedRoute2.Create() 80 81 helpers.WithHelloWorldApp(func(appDir string) { 82 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 83 }) 84 Eventually(helpers.CF("apps")).Should(And(Exit(0), Say(fmt.Sprintf("%s\\s+stopped\\s+0/1", appName)))) 85 86 boundRoute = helpers.NewRoute(spaceName, domainName, "bound-1", "path-3") 87 boundRoute.Create() 88 helpers.MapRouteToApplication(appName, boundRoute.Domain, boundRoute.Host, boundRoute.Path) 89 }) 90 91 It("deletes only the orphaned routes", func() { 92 Eventually(helpers.CF("delete-orphaned-routes", "-f")).Should(SatisfyAll( 93 Exit(0), 94 Say("Getting routes as"), 95 Say(fmt.Sprintf("Deleting route orphan-1.%s/path-1...", domainName)), 96 Say(fmt.Sprintf("Deleting route orphan-2.%s/path-2...", domainName)), 97 Not(Say(fmt.Sprintf("Deleting route bound-1.%s/path-3...", domainName))), 98 Say("OK"), 99 )) 100 }) 101 }) 102 103 Context("when there are more than one page of routes", func() { 104 BeforeEach(func() { 105 var orphanedRoute helpers.Route 106 for i := 0; i < 51; i++ { 107 orphanedRoute = helpers.NewRoute(spaceName, domainName, fmt.Sprintf("orphan-multi-page-%d", i), "") 108 orphanedRoute.Create() 109 } 110 }) 111 It("deletes all the orphaned routes", func() { 112 session := helpers.CF("delete-orphaned-routes", "-f") 113 114 for i := 0; i < 51; i++ { 115 Eventually(session).Should(Say(fmt.Sprintf("Deleting route orphan-multi-page-%d.%s...", i, domainName))) 116 } 117 Eventually(session).Should(Exit(0)) 118 }) 119 }) 120 121 Context("when the force flag is not given", func() { 122 var buffer *Buffer 123 BeforeEach(func() { 124 orphanedRoute := helpers.NewRoute(spaceName, domainName, "orphan", "path") 125 orphanedRoute.Create() 126 }) 127 128 Context("when the user inputs y", func() { 129 BeforeEach(func() { 130 buffer = NewBuffer() 131 buffer.Write([]byte("y\n")) 132 }) 133 134 It("deletes the orphaned routes", func() { 135 session := helpers.CFWithStdin(buffer, "delete-orphaned-routes") 136 Eventually(session).Should(Say("Really delete orphaned routes?")) 137 Eventually(session).Should(SatisfyAll( 138 Exit(0), 139 Say("Getting routes as"), 140 Say(fmt.Sprintf("Deleting route orphan.%s/path...", domainName)), 141 Say("OK"), 142 )) 143 }) 144 }) 145 146 Context("when the user inputs n", func() { 147 BeforeEach(func() { 148 buffer = NewBuffer() 149 buffer.Write([]byte("n\n")) 150 }) 151 152 It("exits without deleting the orphaned routes", func() { 153 session := helpers.CFWithStdin(buffer, "delete-orphaned-routes") 154 Eventually(session).Should(Say("Really delete orphaned routes?")) 155 Eventually(session).Should(SatisfyAll( 156 Exit(0), 157 Not(Say("Getting routes as")), 158 Not(Say(fmt.Sprintf("Deleting route orphan.%s/path...", domainName))), 159 Not(Say("OK")), 160 )) 161 }) 162 }) 163 }) 164 165 Context("when there are no orphaned routes", func() { 166 var ( 167 boundRoute helpers.Route 168 ) 169 170 BeforeEach(func() { 171 helpers.WithHelloWorldApp(func(appDir string) { 172 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 173 }) 174 Eventually(helpers.CF("apps")).Should(And(Exit(0), Say(fmt.Sprintf("%s\\s+stopped\\s+0/1", appName)))) 175 176 boundRoute = helpers.NewRoute(spaceName, domainName, "bound-route", "bound-path") 177 boundRoute.Create() 178 helpers.MapRouteToApplication(appName, boundRoute.Domain, boundRoute.Host, boundRoute.Path) 179 }) 180 181 It("displays OK without deleting any routes", func() { 182 Eventually(helpers.CF("delete-orphaned-routes", "-f")).Should(SatisfyAll( 183 Exit(0), 184 Say("Getting routes as"), 185 Not(Say(fmt.Sprintf("Deleting route bound-route.%s/bound-path...", domainName))), 186 Say("OK"), 187 )) 188 }) 189 }) 190 191 Context("when the orphaned routes are attached to both shared and private domains", func() { 192 var ( 193 orphanedRoute1 helpers.Route 194 orphanedRoute2 helpers.Route 195 sharedDomainName string 196 ) 197 198 BeforeEach(func() { 199 sharedDomainName = helpers.DomainName() 200 sharedDomain := helpers.NewDomain(orgName, sharedDomainName) 201 sharedDomain.Create() 202 sharedDomain.Share() 203 204 orphanedRoute1 = helpers.NewRoute(spaceName, domainName, "orphan-1", "path-1") 205 orphanedRoute2 = helpers.NewRoute(spaceName, sharedDomainName, "orphan-2", "path-2") 206 orphanedRoute1.Create() 207 orphanedRoute2.Create() 208 }) 209 210 It("deletes both the routes", func() { 211 Eventually(helpers.CF("delete-orphaned-routes", "-f")).Should(SatisfyAll( 212 Exit(0), 213 Say("Getting routes as"), 214 Say(fmt.Sprintf("Deleting route orphan-1.%s/path-1...", domainName)), 215 Say(fmt.Sprintf("Deleting route orphan-2.%s/path-2...", sharedDomainName)), 216 Say("OK"), 217 )) 218 }) 219 }) 220 }) 221 })