Skip to content

Commit

Permalink
test: bind-route-service --wait flag
Browse files Browse the repository at this point in the history
  • Loading branch information
blgm committed Oct 30, 2020
1 parent 0eb80d0 commit 50a8595
Showing 1 changed file with 74 additions and 10 deletions.
84 changes: 74 additions & 10 deletions integration/v7/isolated/bind_route_service_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package isolated

import (
"os"
"time"

"code.cloudfoundry.org/cli/integration/helpers"
"code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub"
Expand Down Expand Up @@ -114,6 +115,16 @@ var _ = Describe("bind-route-service command", func() {
username string
)

routeBindingStateForSI := func(serviceInstanceName string) string {
var receiver struct {
Resources []resources.RouteBinding `json:"resources"`
}
helpers.Curl(&receiver, "/v3/service_route_bindings?service_instance_names=%s", serviceInstanceName)
Expect(receiver.Resources).To(HaveLen(1))

return string(receiver.Resources[0].LastOperation.State)
}

BeforeEach(func() {
orgName = helpers.NewOrgName()
spaceName = helpers.NewSpaceName()
Expand Down Expand Up @@ -159,11 +170,7 @@ var _ = Describe("bind-route-service command", func() {

Expect(string(session.Err.Contents())).To(BeEmpty())

var receiver struct {
Resources []resources.RouteBinding `json:"resources"`
}
helpers.Curl(&receiver, "/v3/service_route_bindings?service_instance_names=%s", serviceInstanceName)
Expect(receiver.Resources).To(HaveLen(1))
Expect(routeBindingStateForSI(serviceInstanceName)).To(Equal("succeeded"))
})

When("parameters are specified", func() {
Expand Down Expand Up @@ -219,11 +226,7 @@ var _ = Describe("bind-route-service command", func() {

Expect(string(session.Err.Contents())).To(BeEmpty())

var receiver struct {
Resources []resources.RouteBinding `json:"resources"`
}
helpers.Curl(&receiver, "/v3/service_route_bindings?service_instance_names=%s", serviceInstanceName)
Expect(receiver.Resources).To(HaveLen(1))
Expect(routeBindingStateForSI(serviceInstanceName)).To(Equal("succeeded"))
})

When("parameters are specified", func() {
Expand All @@ -244,6 +247,67 @@ var _ = Describe("bind-route-service command", func() {
})
})

Context("managed route service with asynchronous broker response", func() {
var (
broker *servicebrokerstub.ServiceBrokerStub
serviceInstanceName string
domain string
hostname string
path string
)

BeforeEach(func() {
broker = servicebrokerstub.New().WithRouteService().WithAsyncDelay(time.Second).EnableServiceAccess()
serviceInstanceName = helpers.NewServiceInstanceName()
helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceInstanceName)

domain = helpers.DefaultSharedDomain()
hostname = helpers.NewHostName()
path = helpers.PrefixedRandomName("path")
Eventually(helpers.CF("create-route", domain, "--hostname", hostname, "--path", path)).Should(Exit(0))
})

AfterEach(func() {
broker.Forget()
})

It("starts to create a route binding", func() {
session := helpers.CF(command, domain, "--hostname", hostname, "--path", path, serviceInstanceName)
Eventually(session).Should(Exit(0))

Expect(session.Out).To(SatisfyAll(
Say(`Binding route %s.%s/%s to service instance %s in org %s / space %s as %s\.\.\.\n`, hostname, domain, path, serviceInstanceName, orgName, spaceName, username),
Say(`\n`),
Say(`Create in progress\.\n`),
Say(`OK\n`),
))

Expect(string(session.Err.Contents())).To(BeEmpty())

Expect(routeBindingStateForSI(serviceInstanceName)).To(Equal("in progress"))
})

When("--wait flag specified", func() {
It("waits for completion", func() {
session := helpers.CF(command, domain, "--hostname", hostname, "--path", path, serviceInstanceName, "--wait")
Eventually(session).Should(Exit(0))

Expect(session.Out).To(SatisfyAll(
Say(`Binding route %s.%s/%s to service instance %s in org %s / space %s as %s\.\.\.\n`, hostname, domain, path, serviceInstanceName, orgName, spaceName, username),
Say(`\n`),
Say(`Waiting for the operation to complete\.+\n`),
Say(`\n`),
Say(`Route binding created\.\n`),
Say(`OK\n`),
))

Expect(string(session.Err.Contents())).To(BeEmpty())

Expect(routeBindingStateForSI(serviceInstanceName)).To(Equal("succeeded"))
})
})
})

Context("route binding already exists", func() {
var (
routeServiceURL string
Expand Down

0 comments on commit 50a8595

Please sign in to comment.