github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/route_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     7  
     8  	"code.cloudfoundry.org/cli/actor/actionerror"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
    10  
    11  	. "code.cloudfoundry.org/cli/actor/v7action"
    12  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
    13  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    14  	"code.cloudfoundry.org/cli/types"
    15  	. "github.com/onsi/ginkgo"
    16  	. "github.com/onsi/gomega"
    17  )
    18  
    19  var _ = Describe("Route Actions", func() {
    20  	var (
    21  		actor                     *Actor
    22  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    23  	)
    24  
    25  	BeforeEach(func() {
    26  		actor, fakeCloudControllerClient, _, _, _, _ = NewTestActor()
    27  	})
    28  
    29  	Describe("CreateRoute", func() {
    30  		var (
    31  			warnings   Warnings
    32  			executeErr error
    33  			path       string
    34  		)
    35  
    36  		JustBeforeEach(func() {
    37  			_, warnings, executeErr = actor.CreateRoute("space-guid", "domain-name", "hostname", path)
    38  		})
    39  
    40  		When("the API layer calls are successful", func() {
    41  			BeforeEach(func() {
    42  				fakeCloudControllerClient.GetDomainsReturns(
    43  					[]ccv3.Domain{
    44  						{Name: "domain-name", GUID: "domain-guid"},
    45  					},
    46  					ccv3.Warnings{"get-domains-warning"},
    47  					nil,
    48  				)
    49  
    50  				fakeCloudControllerClient.CreateRouteReturns(
    51  					ccv3.Route{GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", Path: "path-name"},
    52  					ccv3.Warnings{"create-warning-1", "create-warning-2"},
    53  					nil)
    54  			})
    55  
    56  			When("the input path starts with '/'", func() {
    57  				BeforeEach(func() {
    58  					path = "/path-name"
    59  				})
    60  
    61  				It("returns the route with '/<path>' and prints warnings", func() {
    62  					Expect(warnings).To(ConsistOf("create-warning-1", "create-warning-2", "get-domains-warning"))
    63  					Expect(executeErr).ToNot(HaveOccurred())
    64  
    65  					Expect(fakeCloudControllerClient.CreateRouteCallCount()).To(Equal(1))
    66  					passedRoute := fakeCloudControllerClient.CreateRouteArgsForCall(0)
    67  
    68  					Expect(passedRoute).To(Equal(
    69  						ccv3.Route{
    70  							SpaceGUID:  "space-guid",
    71  							DomainGUID: "domain-guid",
    72  							Host:       "hostname",
    73  							Path:       "/path-name",
    74  						},
    75  					))
    76  				})
    77  			})
    78  		})
    79  
    80  		When("the API call to get the domain returns an error", func() {
    81  			When("the cc client returns an RouteNotUniqueError", func() {
    82  				BeforeEach(func() {
    83  					fakeCloudControllerClient.GetDomainsReturns(
    84  						[]ccv3.Domain{
    85  							{Name: "domain-name", GUID: "domain-guid"},
    86  						},
    87  						ccv3.Warnings{"get-domains-warning"},
    88  						nil,
    89  					)
    90  
    91  					fakeCloudControllerClient.GetOrganizationsReturns(
    92  						[]ccv3.Organization{
    93  							{Name: "org-name", GUID: "org-guid"},
    94  						},
    95  						ccv3.Warnings{"get-orgs-warning"},
    96  						nil,
    97  					)
    98  
    99  					fakeCloudControllerClient.GetSpacesReturns(
   100  						[]ccv3.Space{
   101  							{Name: "space-name", GUID: "space-guid"},
   102  						},
   103  						ccv3.Warnings{"get-spaces-warning"},
   104  						nil,
   105  					)
   106  
   107  					fakeCloudControllerClient.CreateRouteReturns(
   108  						ccv3.Route{},
   109  						ccv3.Warnings{"create-route-warning"},
   110  						ccerror.RouteNotUniqueError{
   111  							UnprocessableEntityError: ccerror.UnprocessableEntityError{Message: "some cool error"},
   112  						},
   113  					)
   114  				})
   115  
   116  				It("returns the RouteAlreadyExistsError and warnings", func() {
   117  					Expect(executeErr).To(MatchError(actionerror.RouteAlreadyExistsError{
   118  						Err: ccerror.RouteNotUniqueError{
   119  							UnprocessableEntityError: ccerror.UnprocessableEntityError{Message: "some cool error"},
   120  						},
   121  					}))
   122  					Expect(warnings).To(ConsistOf("get-domains-warning", "create-route-warning"))
   123  				})
   124  			})
   125  
   126  			When("the cc client returns a different error", func() {
   127  				BeforeEach(func() {
   128  					fakeCloudControllerClient.GetDomainsReturns(
   129  						[]ccv3.Domain{},
   130  						ccv3.Warnings{"domain-warning-1", "domain-warning-2"},
   131  						errors.New("api-domains-error"),
   132  					)
   133  				})
   134  
   135  				It("it returns an error and prints warnings", func() {
   136  					Expect(warnings).To(ConsistOf("domain-warning-1", "domain-warning-2"))
   137  					Expect(executeErr).To(MatchError("api-domains-error"))
   138  
   139  					Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
   140  					Expect(fakeCloudControllerClient.CreateRouteCallCount()).To(Equal(0))
   141  				})
   142  			})
   143  		})
   144  	})
   145  
   146  	Describe("GetRoutesBySpace", func() {
   147  		var (
   148  			routes     []Route
   149  			warnings   Warnings
   150  			labels     string
   151  			executeErr error
   152  		)
   153  
   154  		BeforeEach(func() {
   155  			labels = ""
   156  			fakeCloudControllerClient.GetDomainsReturns(
   157  				[]ccv3.Domain{
   158  					{Name: "domain1-name", GUID: "domain1-guid"},
   159  					{Name: "domain2-name", GUID: "domain2-guid"},
   160  				},
   161  				ccv3.Warnings{"get-domains-warning"},
   162  				nil,
   163  			)
   164  
   165  			fakeCloudControllerClient.GetSpacesReturns(
   166  				[]ccv3.Space{
   167  					{Name: "space-name", GUID: "space-guid"},
   168  				},
   169  				ccv3.Warnings{"get-spaces-warning"},
   170  				nil,
   171  			)
   172  
   173  			fakeCloudControllerClient.GetRoutesReturns(
   174  				[]ccv3.Route{
   175  					{GUID: "route1-guid", SpaceGUID: "space-guid", DomainGUID: "domain1-guid", Host: "hostname", URL: "hostname.domain1-name", Destinations: []ccv3.RouteDestination{}},
   176  					{GUID: "route2-guid", SpaceGUID: "space-guid", DomainGUID: "domain2-guid", Path: "/my-path", URL: "domain2-name/my-path", Destinations: []ccv3.RouteDestination{}},
   177  					{GUID: "route3-guid", SpaceGUID: "space-guid", DomainGUID: "domain1-guid", URL: "domain1-name", Destinations: []ccv3.RouteDestination{}},
   178  				},
   179  				ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   180  				nil,
   181  			)
   182  		})
   183  
   184  		JustBeforeEach(func() {
   185  			routes, warnings, executeErr = actor.GetRoutesBySpace("space-guid", labels)
   186  		})
   187  
   188  		When("the API layer calls are successful", func() {
   189  			It("returns the routes and warnings", func() {
   190  				Expect(routes).To(Equal([]Route{
   191  					{GUID: "route1-guid", SpaceGUID: "space-guid", DomainGUID: "domain1-guid", Host: "hostname", DomainName: "domain1-name", SpaceName: "space-name", URL: "hostname.domain1-name", Destinations: []RouteDestination{}},
   192  					{GUID: "route2-guid", SpaceGUID: "space-guid", DomainGUID: "domain2-guid", Path: "/my-path", DomainName: "domain2-name", SpaceName: "space-name", URL: "domain2-name/my-path", Destinations: []RouteDestination{}},
   193  					{GUID: "route3-guid", SpaceGUID: "space-guid", DomainGUID: "domain1-guid", DomainName: "domain1-name", SpaceName: "space-name", URL: "domain1-name", Destinations: []RouteDestination{}},
   194  				}))
   195  				Expect(warnings).To(ConsistOf("get-route-warning-1", "get-route-warning-2", "get-spaces-warning"))
   196  				Expect(executeErr).ToNot(HaveOccurred())
   197  
   198  				Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1))
   199  				query := fakeCloudControllerClient.GetSpacesArgsForCall(0)
   200  				Expect(query).To(HaveLen(1))
   201  				Expect(query[0].Key).To(Equal(ccv3.GUIDFilter))
   202  				Expect(query[0].Values).To(ConsistOf("space-guid"))
   203  
   204  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   205  				query = fakeCloudControllerClient.GetRoutesArgsForCall(0)
   206  				Expect(query).To(HaveLen(1))
   207  				Expect(query[0].Key).To(Equal(ccv3.SpaceGUIDFilter))
   208  				Expect(query[0].Values).To(ConsistOf("space-guid"))
   209  			})
   210  
   211  			When("a label selector is provided", func() {
   212  				BeforeEach(func() {
   213  					labels = "ink=blink"
   214  				})
   215  
   216  				It("passes a label selector query", func() {
   217  					Expect(executeErr).ToNot(HaveOccurred())
   218  
   219  					Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   220  					expectedQuery := []ccv3.Query{
   221  						{Key: ccv3.SpaceGUIDFilter, Values: []string{"space-guid"}},
   222  						{Key: ccv3.LabelSelectorFilter, Values: []string{"ink=blink"}},
   223  					}
   224  					actualQuery := fakeCloudControllerClient.GetRoutesArgsForCall(0)
   225  					Expect(actualQuery).To(Equal(expectedQuery))
   226  				})
   227  			})
   228  		})
   229  
   230  		When("getting routes fails", func() {
   231  			var err = errors.New("failed to get route")
   232  
   233  			BeforeEach(func() {
   234  				fakeCloudControllerClient.GetRoutesReturns(
   235  					nil,
   236  					ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   237  					err)
   238  			})
   239  
   240  			It("returns the error and any warnings", func() {
   241  				Expect(executeErr).To(Equal(err))
   242  				Expect(warnings).To(ConsistOf("get-route-warning-1", "get-route-warning-2"))
   243  			})
   244  		})
   245  
   246  		When("getting spaces fails", func() {
   247  			var err = errors.New("failed to get spaces")
   248  
   249  			BeforeEach(func() {
   250  				fakeCloudControllerClient.GetSpacesReturns(
   251  					nil,
   252  					ccv3.Warnings{"get-spaces-warning"},
   253  					err,
   254  				)
   255  			})
   256  
   257  			It("returns the error and any warnings", func() {
   258  				Expect(executeErr).To(Equal(err))
   259  				Expect(warnings).To(ConsistOf("get-route-warning-1", "get-route-warning-2", "get-spaces-warning"))
   260  			})
   261  		})
   262  
   263  	})
   264  
   265  	Describe("GetRoute", func() {
   266  		BeforeEach(func() {
   267  			fakeCloudControllerClient.GetDomainsReturns(
   268  				[]ccv3.Domain{
   269  					{Name: "domain-name", GUID: "domain-guid"},
   270  				},
   271  				ccv3.Warnings{"get-domains-warning"},
   272  				nil,
   273  			)
   274  
   275  			fakeCloudControllerClient.GetSpacesReturns(
   276  				[]ccv3.Space{
   277  					{Name: "space-name", GUID: "space-guid"},
   278  				},
   279  				ccv3.Warnings{"get-spaces-warning"},
   280  				nil,
   281  			)
   282  
   283  			fakeCloudControllerClient.GetRoutesReturns(
   284  				[]ccv3.Route{
   285  					{
   286  						GUID:       "route1-guid",
   287  						SpaceGUID:  "space-guid",
   288  						DomainGUID: "domain-guid",
   289  						Host:       "hostname",
   290  						URL:        "hostname.domain-name",
   291  						Path:       "/the-path",
   292  						Metadata: &ccv3.Metadata{
   293  							Labels: map[string]types.NullString{
   294  								"some-label": types.NewNullString("some-value"),
   295  							},
   296  						},
   297  					},
   298  				},
   299  				ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   300  				nil,
   301  			)
   302  		})
   303  
   304  		When("the route does not have a host", func() {
   305  			It("returns the route and warnings", func() {
   306  				route, warnings, executeErr := actor.GetRoute("hostname.domain-name", "space-guid")
   307  				Expect(route.GUID).To(Equal("route1-guid"))
   308  				Expect(route.Metadata.Labels["some-label"]).To(Equal(types.NewNullString("some-value")))
   309  				Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-warning-1", "get-route-warning-2", "get-spaces-warning"))
   310  				Expect(executeErr).ToNot(HaveOccurred())
   311  
   312  				Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
   313  				query := fakeCloudControllerClient.GetDomainsArgsForCall(0)
   314  				Expect(query).To(HaveLen(1))
   315  				Expect(query[0].Key).To(Equal(ccv3.NameFilter))
   316  				Expect(query[0].Values).To(ConsistOf("hostname.domain-name"))
   317  
   318  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   319  				query = fakeCloudControllerClient.GetRoutesArgsForCall(0)
   320  				Expect(query).To(HaveLen(4))
   321  				Expect(query[0].Key).To(Equal(ccv3.SpaceGUIDFilter))
   322  				Expect(query[0].Values).To(ConsistOf("space-guid"))
   323  				Expect(query[1].Key).To(Equal(ccv3.DomainGUIDFilter))
   324  				Expect(query[1].Values).To(ConsistOf("domain-guid"))
   325  				Expect(query[2].Key).To(Equal(ccv3.HostsFilter))
   326  				Expect(query[2].Values).To(ConsistOf(""))
   327  				Expect(query[3].Key).To(Equal(ccv3.PathsFilter))
   328  				Expect(query[3].Values).To(ConsistOf(""))
   329  			})
   330  		})
   331  
   332  		When("the route has a host defined", func() {
   333  			BeforeEach(func() {
   334  				fakeCloudControllerClient.GetDomainsReturnsOnCall(
   335  					0,
   336  					[]ccv3.Domain{},
   337  					ccv3.Warnings{"get-domains-warning-1"},
   338  					nil,
   339  				)
   340  
   341  				fakeCloudControllerClient.GetDomainsReturnsOnCall(
   342  					1,
   343  					[]ccv3.Domain{
   344  						{Name: "domain-name", GUID: "domain-guid"},
   345  					},
   346  					ccv3.Warnings{"get-domains-warning-2"},
   347  					nil,
   348  				)
   349  
   350  				fakeCloudControllerClient.GetRoutesReturns(
   351  					[]ccv3.Route{
   352  						{GUID: "route1-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", URL: "hostname.domain-name", Path: "/the-path"},
   353  					},
   354  					ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   355  					nil,
   356  				)
   357  			})
   358  			It("returns the route and warnings", func() {
   359  				route, warnings, executeErr := actor.GetRoute("hostname.domain-name/the-path", "space-guid")
   360  				Expect(route.GUID).To(Equal("route1-guid"))
   361  				Expect(warnings).To(ConsistOf("get-domains-warning-1", "get-domains-warning-2", "get-route-warning-1", "get-route-warning-2", "get-spaces-warning"))
   362  				Expect(executeErr).ToNot(HaveOccurred())
   363  
   364  				Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(2))
   365  				query := fakeCloudControllerClient.GetDomainsArgsForCall(0)
   366  				Expect(query).To(HaveLen(1))
   367  				Expect(query[0].Key).To(Equal(ccv3.NameFilter))
   368  				Expect(query[0].Values).To(ConsistOf("hostname.domain-name"))
   369  				query = fakeCloudControllerClient.GetDomainsArgsForCall(1)
   370  				Expect(query).To(HaveLen(1))
   371  				Expect(query[0].Key).To(Equal(ccv3.NameFilter))
   372  				Expect(query[0].Values).To(ConsistOf("domain-name"))
   373  
   374  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   375  				query = fakeCloudControllerClient.GetRoutesArgsForCall(0)
   376  				Expect(query).To(HaveLen(4))
   377  				Expect(query[0].Key).To(Equal(ccv3.SpaceGUIDFilter))
   378  				Expect(query[0].Values).To(ConsistOf("space-guid"))
   379  				Expect(query[1].Key).To(Equal(ccv3.DomainGUIDFilter))
   380  				Expect(query[1].Values).To(ConsistOf("domain-guid"))
   381  				Expect(query[2].Key).To(Equal(ccv3.HostsFilter))
   382  				Expect(query[2].Values).To(ConsistOf("hostname"))
   383  				Expect(query[3].Key).To(Equal(ccv3.PathsFilter))
   384  				Expect(query[3].Values).To(ConsistOf("/the-path"))
   385  			})
   386  		})
   387  
   388  		When("invalid domain cannot be found", func() {
   389  			BeforeEach(func() {
   390  				fakeCloudControllerClient.GetDomainsReturns(
   391  					[]ccv3.Domain{},
   392  					ccv3.Warnings{"get-domains-warning"},
   393  					nil,
   394  				)
   395  			})
   396  
   397  			It("returns the error and any warnings", func() {
   398  				_, warnings, executeErr := actor.GetRoute("unsplittabledomain/the-path", "space-guid")
   399  				Expect(warnings).To(ConsistOf("get-domains-warning"))
   400  				Expect(executeErr).To(MatchError(actionerror.DomainNotFoundError{Name: "unsplittabledomain"}))
   401  			})
   402  		})
   403  
   404  		When("the route does not exist", func() {
   405  			BeforeEach(func() {
   406  				fakeCloudControllerClient.GetRoutesReturns(
   407  					[]ccv3.Route{},
   408  					ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   409  					nil,
   410  				)
   411  			})
   412  
   413  			It("returns the error and any warnings", func() {
   414  				_, warnings, executeErr := actor.GetRoute("unsplittabledomain/the-path", "space-guid")
   415  				Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-warning-1", "get-route-warning-2"))
   416  				Expect(executeErr).To(MatchError(actionerror.RouteNotFoundError{Host: "", DomainName: "unsplittabledomain", Path: "/the-path"}))
   417  			})
   418  		})
   419  
   420  		When("getting domain fails", func() {
   421  			var err = errors.New("failed to get domain")
   422  
   423  			BeforeEach(func() {
   424  				fakeCloudControllerClient.GetDomainsReturns(
   425  					nil,
   426  					ccv3.Warnings{"get-domains-warning"},
   427  					err,
   428  				)
   429  			})
   430  
   431  			It("returns the error and any warnings", func() {
   432  				_, warnings, executeErr := actor.GetRoute("hostname.domain-name/the-path", "space-guid")
   433  				Expect(warnings).To(ConsistOf("get-domains-warning"))
   434  				Expect(executeErr).To(Equal(err))
   435  			})
   436  		})
   437  
   438  		When("getting route fails", func() {
   439  			var err = errors.New("failed to get route")
   440  
   441  			BeforeEach(func() {
   442  				fakeCloudControllerClient.GetRoutesReturns(
   443  					nil,
   444  					ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   445  					err)
   446  			})
   447  
   448  			It("returns the error and any warnings", func() {
   449  				_, warnings, executeErr := actor.GetRoute("hostname.domain-name/the-path", "space-guid")
   450  				Expect(executeErr).To(Equal(err))
   451  				Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-warning-1", "get-route-warning-2"))
   452  			})
   453  		})
   454  
   455  		When("getting route spaces fails", func() {
   456  			var err = errors.New("failed to get route spaces")
   457  
   458  			BeforeEach(func() {
   459  				fakeCloudControllerClient.GetSpacesReturns(
   460  					nil,
   461  					ccv3.Warnings{"get-route-space-warning-1", "get-route-space-warning-2"},
   462  					err)
   463  			})
   464  
   465  			It("returns the error and any warnings", func() {
   466  				_, warnings, executeErr := actor.GetRoute("hostname.domain-name/the-path", "space-guid")
   467  				Expect(executeErr).To(Equal(err))
   468  				Expect(warnings).To(ConsistOf("get-domains-warning", "get-route-space-warning-1", "get-route-space-warning-2", "get-route-warning-1", "get-route-warning-2"))
   469  			})
   470  		})
   471  
   472  	})
   473  
   474  	Describe("GetRoutesByOrg", func() {
   475  		var (
   476  			routes     []Route
   477  			warnings   Warnings
   478  			executeErr error
   479  			labels     string
   480  		)
   481  
   482  		BeforeEach(func() {
   483  			labels = ""
   484  			fakeCloudControllerClient.GetDomainsReturns(
   485  				[]ccv3.Domain{
   486  					{Name: "domain1-name", GUID: "domain1-guid"},
   487  					{Name: "domain2-name", GUID: "domain2-guid"},
   488  				},
   489  				ccv3.Warnings{"get-domains-warning"},
   490  				nil,
   491  			)
   492  
   493  			fakeCloudControllerClient.GetSpacesReturns(
   494  				[]ccv3.Space{
   495  					{Name: "space1-name", GUID: "space1-guid"},
   496  					{Name: "space2-name", GUID: "space2-guid"},
   497  				},
   498  				ccv3.Warnings{"get-spaces-warning"},
   499  				nil,
   500  			)
   501  
   502  			fakeCloudControllerClient.GetRoutesReturns(
   503  				[]ccv3.Route{
   504  					{GUID: "route1-guid", SpaceGUID: "space1-guid", URL: "hostname.domain1-name", DomainGUID: "domain1-guid", Host: "hostname"},
   505  					{GUID: "route2-guid", SpaceGUID: "space2-guid", URL: "domain2-name/my-path", DomainGUID: "domain2-guid", Path: "/my-path"},
   506  					{GUID: "route3-guid", SpaceGUID: "space1-guid", URL: "domain1-name", DomainGUID: "domain1-guid"},
   507  				},
   508  				ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   509  				nil,
   510  			)
   511  		})
   512  
   513  		JustBeforeEach(func() {
   514  			routes, warnings, executeErr = actor.GetRoutesByOrg("org-guid", labels)
   515  		})
   516  
   517  		When("the API layer calls are successful", func() {
   518  			It("returns the routes and warnings", func() {
   519  				Expect(routes).To(Equal([]Route{
   520  					{
   521  						GUID:         "route1-guid",
   522  						SpaceGUID:    "space1-guid",
   523  						DomainGUID:   "domain1-guid",
   524  						Host:         "hostname",
   525  						DomainName:   "domain1-name",
   526  						SpaceName:    "space1-name",
   527  						URL:          "hostname.domain1-name",
   528  						Destinations: []RouteDestination{},
   529  					},
   530  					{
   531  						GUID:         "route2-guid",
   532  						SpaceGUID:    "space2-guid",
   533  						DomainGUID:   "domain2-guid",
   534  						Path:         "/my-path",
   535  						DomainName:   "domain2-name",
   536  						SpaceName:    "space2-name",
   537  						URL:          "domain2-name/my-path",
   538  						Destinations: []RouteDestination{},
   539  					},
   540  					{
   541  						GUID:         "route3-guid",
   542  						SpaceGUID:    "space1-guid",
   543  						DomainGUID:   "domain1-guid",
   544  						DomainName:   "domain1-name",
   545  						SpaceName:    "space1-name",
   546  						URL:          "domain1-name",
   547  						Destinations: []RouteDestination{},
   548  					},
   549  				}))
   550  				Expect(warnings).To(ConsistOf("get-route-warning-1", "get-route-warning-2", "get-spaces-warning"))
   551  				Expect(executeErr).ToNot(HaveOccurred())
   552  
   553  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   554  				query := fakeCloudControllerClient.GetRoutesArgsForCall(0)
   555  				Expect(query).To(HaveLen(1))
   556  				Expect(query[0].Key).To(Equal(ccv3.OrganizationGUIDFilter))
   557  				Expect(query[0].Values).To(ConsistOf("org-guid"))
   558  
   559  				Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1))
   560  				query = fakeCloudControllerClient.GetSpacesArgsForCall(0)
   561  				Expect(query).To(HaveLen(1))
   562  				Expect(query[0].Key).To(Equal(ccv3.GUIDFilter))
   563  				Expect(query[0].Values).To(ConsistOf("space1-guid", "space2-guid"))
   564  			})
   565  
   566  			When("a label selector is provided", func() {
   567  				BeforeEach(func() {
   568  					labels = "env=prod"
   569  				})
   570  
   571  				It("converts it into a query key", func() {
   572  					Expect(executeErr).ToNot(HaveOccurred())
   573  
   574  					Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   575  					expectedQuery := []ccv3.Query{
   576  						{Key: ccv3.OrganizationGUIDFilter, Values: []string{"org-guid"}},
   577  						{Key: ccv3.LabelSelectorFilter, Values: []string{"env=prod"}},
   578  					}
   579  					actualQuery := fakeCloudControllerClient.GetRoutesArgsForCall(0)
   580  					Expect(actualQuery).To(Equal(expectedQuery))
   581  				})
   582  			})
   583  		})
   584  
   585  		When("getting routes fails", func() {
   586  			var err = errors.New("failed to get route")
   587  
   588  			BeforeEach(func() {
   589  				fakeCloudControllerClient.GetRoutesReturns(
   590  					nil,
   591  					ccv3.Warnings{"get-route-warning-1", "get-route-warning-2"},
   592  					err)
   593  			})
   594  
   595  			It("returns the error and any warnings", func() {
   596  				Expect(executeErr).To(Equal(err))
   597  				Expect(warnings).To(ConsistOf("get-route-warning-1", "get-route-warning-2"))
   598  			})
   599  		})
   600  
   601  		When("getting spaces fails", func() {
   602  			var err = errors.New("failed to get spaces")
   603  
   604  			BeforeEach(func() {
   605  				fakeCloudControllerClient.GetSpacesReturns(
   606  					nil,
   607  					ccv3.Warnings{"get-spaces-warning"},
   608  					err,
   609  				)
   610  			})
   611  
   612  			It("returns the error and any warnings", func() {
   613  				Expect(executeErr).To(Equal(err))
   614  				Expect(warnings).To(ConsistOf("get-route-warning-1", "get-route-warning-2", "get-spaces-warning"))
   615  			})
   616  		})
   617  	})
   618  
   619  	Describe("GetRouteSummaries", func() {
   620  		var (
   621  			routes         []Route
   622  			routeSummaries []RouteSummary
   623  			warnings       Warnings
   624  			executeErr     error
   625  		)
   626  
   627  		BeforeEach(func() {
   628  			routes = []Route{
   629  				{
   630  					GUID: "route-guid-1",
   631  					Destinations: []RouteDestination{
   632  						{
   633  							App: RouteDestinationApp{
   634  								GUID: "app-guid-1",
   635  							},
   636  						},
   637  					},
   638  				},
   639  				{
   640  					GUID: "route-guid-2",
   641  					Destinations: []RouteDestination{
   642  						{
   643  							App: RouteDestinationApp{
   644  								GUID: "app-guid-1",
   645  							},
   646  						},
   647  						{
   648  							App: RouteDestinationApp{
   649  								GUID: "app-guid-2",
   650  							},
   651  						},
   652  					},
   653  				},
   654  				{
   655  					GUID:         "route-guid-3",
   656  					Destinations: []RouteDestination{},
   657  				},
   658  			}
   659  
   660  			fakeCloudControllerClient.GetApplicationsReturns(
   661  				[]ccv3.Application{
   662  					{
   663  						GUID: "app-guid-1",
   664  						Name: "app-name-1",
   665  					},
   666  					{
   667  						GUID: "app-guid-2",
   668  						Name: "app-name-2",
   669  					},
   670  				},
   671  				ccv3.Warnings{"get-apps-warning"},
   672  				nil,
   673  			)
   674  		})
   675  
   676  		JustBeforeEach(func() {
   677  			routeSummaries, warnings, executeErr = actor.GetRouteSummaries(routes)
   678  		})
   679  
   680  		When("the API layer calls are successful", func() {
   681  			It("returns the routes and warnings", func() {
   682  				Expect(routeSummaries).To(Equal([]RouteSummary{
   683  					{
   684  						Route:    Route{GUID: "route-guid-1", Destinations: []RouteDestination{{App: RouteDestinationApp{GUID: "app-guid-1"}}}},
   685  						AppNames: []string{"app-name-1"},
   686  					},
   687  					{
   688  						Route:    Route{GUID: "route-guid-2", Destinations: []RouteDestination{{App: RouteDestinationApp{GUID: "app-guid-1"}}, {App: RouteDestinationApp{GUID: "app-guid-2"}}}},
   689  						AppNames: []string{"app-name-1", "app-name-2"},
   690  					},
   691  					{
   692  						Route:    Route{GUID: "route-guid-3", Destinations: []RouteDestination{}},
   693  						AppNames: nil,
   694  					},
   695  				}))
   696  				Expect(warnings).To(ConsistOf("get-apps-warning"))
   697  				Expect(executeErr).ToNot(HaveOccurred())
   698  
   699  				Expect(fakeCloudControllerClient.GetApplicationsCallCount()).To(Equal(1))
   700  				query := fakeCloudControllerClient.GetApplicationsArgsForCall(0)
   701  				Expect(query).To(ConsistOf(
   702  					ccv3.Query{Key: ccv3.GUIDFilter, Values: []string{"app-guid-1", "app-guid-2"}},
   703  				))
   704  			})
   705  		})
   706  
   707  		When("getting apps fails", func() {
   708  			var err = errors.New("failed to get apps")
   709  
   710  			BeforeEach(func() {
   711  				fakeCloudControllerClient.GetApplicationsReturns(
   712  					nil,
   713  					ccv3.Warnings{"get-apps-warning"},
   714  					err,
   715  				)
   716  			})
   717  
   718  			It("returns the error and any warnings", func() {
   719  				Expect(executeErr).To(Equal(err))
   720  				Expect(warnings).To(ConsistOf("get-apps-warning"))
   721  			})
   722  		})
   723  	})
   724  
   725  	Describe("GetRouteDestinations", func() {
   726  		var (
   727  			routeGUID    string
   728  			destinations []RouteDestination
   729  
   730  			executeErr error
   731  			warnings   Warnings
   732  		)
   733  
   734  		JustBeforeEach(func() {
   735  			destinations, warnings, executeErr = actor.GetRouteDestinations(routeGUID)
   736  		})
   737  
   738  		BeforeEach(func() {
   739  			routeGUID = "route-guid"
   740  		})
   741  
   742  		When("the cloud controller client errors", func() {
   743  			BeforeEach(func() {
   744  				fakeCloudControllerClient.GetRouteDestinationsReturns(
   745  					nil,
   746  					ccv3.Warnings{"get-destinations-warning"},
   747  					errors.New("get-destinations-error"),
   748  				)
   749  			})
   750  
   751  			It("returns the error and warnings", func() {
   752  				Expect(executeErr).To(MatchError(errors.New("get-destinations-error")))
   753  				Expect(warnings).To(ConsistOf("get-destinations-warning"))
   754  			})
   755  		})
   756  
   757  		When("the cloud controller client succeeds", func() {
   758  			BeforeEach(func() {
   759  				fakeCloudControllerClient.GetRouteDestinationsReturns(
   760  					[]ccv3.RouteDestination{
   761  						{GUID: "destination-guid-1", App: ccv3.RouteDestinationApp{GUID: "app-guid-1"}},
   762  						{GUID: "destination-guid-2", App: ccv3.RouteDestinationApp{GUID: "app-guid-2"}},
   763  					},
   764  					ccv3.Warnings{"get-destinations-warning"},
   765  					nil,
   766  				)
   767  			})
   768  
   769  			It("returns the destinations and warnings", func() {
   770  				Expect(executeErr).ToNot(HaveOccurred())
   771  				Expect(warnings).To(ConsistOf("get-destinations-warning"))
   772  				Expect(destinations).To(ConsistOf(
   773  					RouteDestination{GUID: "destination-guid-1", App: RouteDestinationApp{GUID: "app-guid-1"}},
   774  					RouteDestination{GUID: "destination-guid-2", App: RouteDestinationApp{GUID: "app-guid-2"}},
   775  				))
   776  			})
   777  		})
   778  	})
   779  
   780  	Describe("GetRouteDestinationByAppGUID", func() {
   781  		var (
   782  			routeGUID   = "route-guid"
   783  			appGUID     = "app-guid"
   784  			destination RouteDestination
   785  
   786  			executeErr error
   787  			warnings   Warnings
   788  		)
   789  
   790  		JustBeforeEach(func() {
   791  			destination, warnings, executeErr = actor.GetRouteDestinationByAppGUID(routeGUID, appGUID)
   792  		})
   793  
   794  		When("the cloud controller client errors", func() {
   795  			BeforeEach(func() {
   796  				fakeCloudControllerClient.GetRouteDestinationsReturns(
   797  					nil,
   798  					ccv3.Warnings{"get-destinations-warning"},
   799  					errors.New("get-destinations-error"),
   800  				)
   801  			})
   802  
   803  			It("returns the error and warnings", func() {
   804  				Expect(destination).To(Equal(RouteDestination{}))
   805  				Expect(executeErr).To(MatchError(errors.New("get-destinations-error")))
   806  				Expect(warnings).To(ConsistOf("get-destinations-warning"))
   807  			})
   808  		})
   809  
   810  		When("the cloud controller client succeeds with a matching app", func() {
   811  			BeforeEach(func() {
   812  				fakeCloudControllerClient.GetRouteDestinationsReturns(
   813  					[]ccv3.RouteDestination{
   814  						{
   815  							GUID: "destination-guid-1",
   816  							App:  ccv3.RouteDestinationApp{GUID: appGUID, Process: struct{ Type string }{Type: "worker"}},
   817  						},
   818  						{
   819  							GUID: "destination-guid-2",
   820  							App:  ccv3.RouteDestinationApp{GUID: appGUID, Process: struct{ Type string }{Type: constant.ProcessTypeWeb}},
   821  						},
   822  						{
   823  							GUID: "destination-guid-3",
   824  							App:  ccv3.RouteDestinationApp{GUID: "app-guid-2", Process: struct{ Type string }{Type: constant.ProcessTypeWeb}},
   825  						},
   826  					},
   827  					ccv3.Warnings{"get-destinations-warning"},
   828  					nil,
   829  				)
   830  			})
   831  
   832  			It("returns the matching destination and warnings", func() {
   833  				Expect(executeErr).ToNot(HaveOccurred())
   834  				Expect(warnings).To(ConsistOf("get-destinations-warning"))
   835  				Expect(destination).To(Equal(RouteDestination{
   836  					GUID: "destination-guid-2",
   837  					App:  RouteDestinationApp{GUID: appGUID, Process: struct{ Type string }{Type: constant.ProcessTypeWeb}},
   838  				}))
   839  			})
   840  		})
   841  
   842  		When("the cloud controller client succeeds without a matching app", func() {
   843  			BeforeEach(func() {
   844  				fakeCloudControllerClient.GetRouteDestinationsReturns(
   845  					[]ccv3.RouteDestination{
   846  						{
   847  							GUID: "destination-guid-1",
   848  							App:  ccv3.RouteDestinationApp{GUID: appGUID, Process: struct{ Type string }{Type: "worker"}},
   849  						},
   850  						{
   851  							GUID: "destination-guid-2",
   852  							App:  ccv3.RouteDestinationApp{GUID: "app-guid-2", Process: struct{ Type string }{Type: constant.ProcessTypeWeb}},
   853  						},
   854  						{
   855  							GUID: "destination-guid-3",
   856  							App:  ccv3.RouteDestinationApp{GUID: "app-guid-3", Process: struct{ Type string }{Type: constant.ProcessTypeWeb}},
   857  						},
   858  					},
   859  					ccv3.Warnings{"get-destinations-warning"},
   860  					nil,
   861  				)
   862  			})
   863  
   864  			It("returns an error and warnings", func() {
   865  				Expect(destination).To(Equal(RouteDestination{}))
   866  				Expect(executeErr).To(MatchError(actionerror.RouteDestinationNotFoundError{
   867  					AppGUID:     appGUID,
   868  					ProcessType: constant.ProcessTypeWeb,
   869  					RouteGUID:   routeGUID,
   870  				}))
   871  				Expect(warnings).To(ConsistOf("get-destinations-warning"))
   872  			})
   873  		})
   874  	})
   875  
   876  	Describe("DeleteRoute", func() {
   877  		When("deleting a route", func() {
   878  			BeforeEach(func() {
   879  				fakeCloudControllerClient.GetDomainsReturns(
   880  					[]ccv3.Domain{
   881  						{GUID: "domain-guid"},
   882  					},
   883  					ccv3.Warnings{"get-domains-warning"},
   884  					nil,
   885  				)
   886  				fakeCloudControllerClient.GetRoutesReturns(
   887  					[]ccv3.Route{
   888  						{GUID: "route-guid"},
   889  					},
   890  					ccv3.Warnings{"get-routes-warning"},
   891  					nil,
   892  				)
   893  				fakeCloudControllerClient.DeleteRouteReturns(
   894  					ccv3.JobURL("https://jobs/job_guid"),
   895  					ccv3.Warnings{"delete-warning"},
   896  					nil,
   897  				)
   898  			})
   899  
   900  			It("delegates to the cloud controller client", func() {
   901  				warnings, executeErr := actor.DeleteRoute("domain.com", "hostname", "/path")
   902  				Expect(executeErr).NotTo(HaveOccurred())
   903  				Expect(warnings).To(ConsistOf("get-domains-warning", "get-routes-warning", "delete-warning"))
   904  
   905  				// Get the domain
   906  				Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
   907  				query := fakeCloudControllerClient.GetDomainsArgsForCall(0)
   908  				Expect(query).To(ConsistOf([]ccv3.Query{
   909  					{Key: ccv3.NameFilter, Values: []string{"domain.com"}},
   910  				}))
   911  
   912  				// Get the route based on the domain GUID
   913  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   914  				query = fakeCloudControllerClient.GetRoutesArgsForCall(0)
   915  				Expect(query).To(ConsistOf([]ccv3.Query{
   916  					{Key: "domain_guids", Values: []string{"domain-guid"}},
   917  					{Key: "hosts", Values: []string{"hostname"}},
   918  					{Key: "paths", Values: []string{"/path"}},
   919  				}))
   920  
   921  				// Delete the route asynchronously
   922  				Expect(fakeCloudControllerClient.DeleteRouteCallCount()).To(Equal(1))
   923  				passedRouteGuid := fakeCloudControllerClient.DeleteRouteArgsForCall(0)
   924  				Expect(passedRouteGuid).To(Equal("route-guid"))
   925  
   926  				// Poll the delete job
   927  				Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
   928  				responseJobUrl := fakeCloudControllerClient.PollJobArgsForCall(0)
   929  				Expect(responseJobUrl).To(Equal(ccv3.JobURL("https://jobs/job_guid")))
   930  			})
   931  
   932  			It("only passes in queries that are not blank", func() {
   933  				_, err := actor.DeleteRoute("domain.com", "", "")
   934  				Expect(err).NotTo(HaveOccurred())
   935  
   936  				Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
   937  				query := fakeCloudControllerClient.GetDomainsArgsForCall(0)
   938  				Expect(query).To(ConsistOf([]ccv3.Query{
   939  					{Key: ccv3.NameFilter, Values: []string{"domain.com"}},
   940  				}))
   941  
   942  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
   943  				query = fakeCloudControllerClient.GetRoutesArgsForCall(0)
   944  				Expect(query).To(ConsistOf([]ccv3.Query{
   945  					{Key: "domain_guids", Values: []string{"domain-guid"}},
   946  					{Key: "hosts", Values: []string{""}},
   947  					{Key: "paths", Values: []string{""}},
   948  				}))
   949  
   950  				Expect(fakeCloudControllerClient.DeleteRouteCallCount()).To(Equal(1))
   951  				passedRouteGuid := fakeCloudControllerClient.DeleteRouteArgsForCall(0)
   952  
   953  				Expect(passedRouteGuid).To(Equal("route-guid"))
   954  			})
   955  
   956  			When("getting domains fails", func() {
   957  				BeforeEach(func() {
   958  					fakeCloudControllerClient.GetDomainsReturns(
   959  						nil,
   960  						ccv3.Warnings{"get-domains-warning"},
   961  						errors.New("get-domains-error"),
   962  					)
   963  				})
   964  
   965  				It("returns the error", func() {
   966  					warnings, err := actor.DeleteRoute("domain.com", "hostname", "path")
   967  					Expect(err).To(MatchError("get-domains-error"))
   968  					Expect(warnings).To(ConsistOf("get-domains-warning"))
   969  				})
   970  			})
   971  
   972  			When("getting routes fails", func() {
   973  				BeforeEach(func() {
   974  					fakeCloudControllerClient.GetRoutesReturns(
   975  						nil,
   976  						ccv3.Warnings{"get-routes-warning"},
   977  						errors.New("get-routes-error"),
   978  					)
   979  				})
   980  
   981  				It("returns the error", func() {
   982  					warnings, err := actor.DeleteRoute("domain.com", "hostname", "path")
   983  					Expect(err).To(MatchError("get-routes-error"))
   984  					Expect(warnings).To(ConsistOf("get-domains-warning", "get-routes-warning"))
   985  				})
   986  			})
   987  
   988  			When("deleting route fails", func() {
   989  				BeforeEach(func() {
   990  					fakeCloudControllerClient.DeleteRouteReturns(
   991  						"",
   992  						ccv3.Warnings{"delete-route-warning"},
   993  						errors.New("delete-route-error"),
   994  					)
   995  				})
   996  
   997  				It("returns the error", func() {
   998  					warnings, err := actor.DeleteRoute("domain.com", "hostname", "path")
   999  					Expect(err).To(MatchError("delete-route-error"))
  1000  					Expect(warnings).To(ConsistOf("get-domains-warning", "get-routes-warning", "delete-route-warning"))
  1001  				})
  1002  			})
  1003  
  1004  			When("polling the job fails", func() {
  1005  				BeforeEach(func() {
  1006  					fakeCloudControllerClient.PollJobReturns(
  1007  						ccv3.Warnings{"poll-job-warning"},
  1008  						errors.New("async-route-delete-error"),
  1009  					)
  1010  				})
  1011  
  1012  				It("returns the error", func() {
  1013  					warnings, err := actor.DeleteRoute("domain.com", "hostname", "path")
  1014  					Expect(err).To(MatchError("async-route-delete-error"))
  1015  					Expect(warnings).To(ConsistOf(
  1016  						"get-domains-warning",
  1017  						"get-routes-warning",
  1018  						"delete-warning",
  1019  						"poll-job-warning",
  1020  					))
  1021  				})
  1022  			})
  1023  
  1024  			When("no routes are returned", func() {
  1025  				BeforeEach(func() {
  1026  					fakeCloudControllerClient.GetRoutesReturns(
  1027  						[]ccv3.Route{},
  1028  						ccv3.Warnings{"get-routes-warning"},
  1029  						nil,
  1030  					)
  1031  				})
  1032  
  1033  				It("returns the error", func() {
  1034  					warnings, err := actor.DeleteRoute("domain.com", "hostname", "/path")
  1035  					Expect(err).To(Equal(actionerror.RouteNotFoundError{
  1036  						DomainName: "domain.com",
  1037  						Host:       "hostname",
  1038  						Path:       "/path",
  1039  					}))
  1040  					Expect(warnings).To(ConsistOf("get-domains-warning", "get-routes-warning"))
  1041  				})
  1042  			})
  1043  		})
  1044  	})
  1045  
  1046  	Describe("GetRouteByAttributes", func() {
  1047  		var (
  1048  			domainName = "some-domain.com"
  1049  			domainGUID = "domain-guid"
  1050  			hostname   = "hostname"
  1051  			path       = "/path"
  1052  
  1053  			executeErr error
  1054  			warnings   Warnings
  1055  			route      Route
  1056  		)
  1057  
  1058  		JustBeforeEach(func() {
  1059  			route, warnings, executeErr = actor.GetRouteByAttributes(domainName, domainGUID, hostname, path)
  1060  		})
  1061  
  1062  		When("The cc client errors", func() {
  1063  			BeforeEach(func() {
  1064  				fakeCloudControllerClient.GetRoutesReturns(nil, ccv3.Warnings{"get-routes-warning"}, errors.New("scooby"))
  1065  			})
  1066  
  1067  			It("returns and empty route, warnings, and the error", func() {
  1068  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
  1069  				actualQueries := fakeCloudControllerClient.GetRoutesArgsForCall(0)
  1070  				Expect(actualQueries).To(ConsistOf(
  1071  					ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{domainGUID}},
  1072  					ccv3.Query{Key: ccv3.HostsFilter, Values: []string{hostname}},
  1073  					ccv3.Query{Key: ccv3.PathsFilter, Values: []string{path}},
  1074  				))
  1075  
  1076  				Expect(warnings).To(ConsistOf("get-routes-warning"))
  1077  				Expect(executeErr).To(MatchError(errors.New("scooby")))
  1078  			})
  1079  
  1080  		})
  1081  
  1082  		When("the cc client succeeds and a route is found", func() {
  1083  			BeforeEach(func() {
  1084  				fakeCloudControllerClient.GetRoutesReturns([]ccv3.Route{{
  1085  					DomainGUID: domainGUID,
  1086  					Host:       hostname,
  1087  					Path:       path,
  1088  				}}, ccv3.Warnings{"get-routes-warning"}, nil)
  1089  			})
  1090  
  1091  			It("returns the route and the warnings", func() {
  1092  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
  1093  				actualQueries := fakeCloudControllerClient.GetRoutesArgsForCall(0)
  1094  				Expect(actualQueries).To(ConsistOf(
  1095  					ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{domainGUID}},
  1096  					ccv3.Query{Key: ccv3.HostsFilter, Values: []string{hostname}},
  1097  					ccv3.Query{Key: ccv3.PathsFilter, Values: []string{path}},
  1098  				))
  1099  
  1100  				Expect(warnings).To(ConsistOf("get-routes-warning"))
  1101  				Expect(executeErr).ToNot(HaveOccurred())
  1102  				Expect(route).To(Equal(Route{
  1103  					DomainGUID: domainGUID,
  1104  					Host:       hostname,
  1105  					Path:       path,
  1106  				}))
  1107  			})
  1108  		})
  1109  
  1110  		When("the cc client succeeds and a route is not found", func() {
  1111  			BeforeEach(func() {
  1112  				fakeCloudControllerClient.GetRoutesReturns([]ccv3.Route{}, ccv3.Warnings{"get-routes-warning"}, nil)
  1113  			})
  1114  
  1115  			It("returns the route and the warnings", func() {
  1116  				Expect(fakeCloudControllerClient.GetRoutesCallCount()).To(Equal(1))
  1117  				actualQueries := fakeCloudControllerClient.GetRoutesArgsForCall(0)
  1118  				Expect(actualQueries).To(ConsistOf(
  1119  					ccv3.Query{Key: ccv3.DomainGUIDFilter, Values: []string{domainGUID}},
  1120  					ccv3.Query{Key: ccv3.HostsFilter, Values: []string{hostname}},
  1121  					ccv3.Query{Key: ccv3.PathsFilter, Values: []string{path}},
  1122  				))
  1123  
  1124  				Expect(warnings).To(ConsistOf("get-routes-warning"))
  1125  				Expect(executeErr).To(MatchError(actionerror.RouteNotFoundError{
  1126  					DomainName: domainName,
  1127  					DomainGUID: domainGUID,
  1128  					Host:       hostname,
  1129  					Path:       path,
  1130  				}))
  1131  			})
  1132  		})
  1133  	})
  1134  
  1135  	Describe("MapRoute", func() {
  1136  		var (
  1137  			routeGUID string
  1138  			appGUID   string
  1139  
  1140  			executeErr error
  1141  			warnings   Warnings
  1142  		)
  1143  
  1144  		JustBeforeEach(func() {
  1145  			warnings, executeErr = actor.MapRoute(routeGUID, appGUID)
  1146  		})
  1147  
  1148  		BeforeEach(func() {
  1149  			routeGUID = "route-guid"
  1150  			appGUID = "app-guid"
  1151  		})
  1152  
  1153  		When("the cloud controller client errors", func() {
  1154  			BeforeEach(func() {
  1155  				fakeCloudControllerClient.MapRouteReturns(ccv3.Warnings{"map-route-warning"}, errors.New("map-route-error"))
  1156  			})
  1157  
  1158  			It("returns the error and warnings", func() {
  1159  				Expect(executeErr).To(MatchError(errors.New("map-route-error")))
  1160  				Expect(warnings).To(ConsistOf("map-route-warning"))
  1161  			})
  1162  		})
  1163  
  1164  		When("the cloud controller client succeeds", func() {
  1165  			BeforeEach(func() {
  1166  				fakeCloudControllerClient.MapRouteReturns(ccv3.Warnings{"map-route-warning"}, nil)
  1167  			})
  1168  
  1169  			It("returns the error and warnings", func() {
  1170  				Expect(executeErr).ToNot(HaveOccurred())
  1171  				Expect(warnings).To(ConsistOf("map-route-warning"))
  1172  			})
  1173  		})
  1174  	})
  1175  
  1176  	Describe("UnmapRoute", func() {
  1177  		var (
  1178  			routeGUID       string
  1179  			destinationGUID string
  1180  
  1181  			executeErr error
  1182  			warnings   Warnings
  1183  		)
  1184  
  1185  		JustBeforeEach(func() {
  1186  			warnings, executeErr = actor.UnmapRoute(routeGUID, destinationGUID)
  1187  		})
  1188  
  1189  		BeforeEach(func() {
  1190  			routeGUID = "route-guid"
  1191  			destinationGUID = "destination-guid"
  1192  		})
  1193  
  1194  		When("the cloud controller client errors", func() {
  1195  			BeforeEach(func() {
  1196  				fakeCloudControllerClient.UnmapRouteReturns(ccv3.Warnings{"unmap-route-warning"}, errors.New("unmap-route-error"))
  1197  			})
  1198  
  1199  			It("returns the error and warnings", func() {
  1200  				Expect(executeErr).To(MatchError(errors.New("unmap-route-error")))
  1201  				Expect(warnings).To(ConsistOf("unmap-route-warning"))
  1202  			})
  1203  		})
  1204  
  1205  		When("the cloud controller client succeeds", func() {
  1206  			BeforeEach(func() {
  1207  				fakeCloudControllerClient.UnmapRouteReturns(ccv3.Warnings{"unmap-route-warning"}, nil)
  1208  			})
  1209  
  1210  			It("returns the error and warnings", func() {
  1211  				Expect(executeErr).ToNot(HaveOccurred())
  1212  				Expect(warnings).To(ConsistOf("unmap-route-warning"))
  1213  			})
  1214  		})
  1215  	})
  1216  
  1217  	Describe("DeleteOrphanedRoutes", func() {
  1218  		var (
  1219  			spaceGUID string
  1220  
  1221  			warnings   Warnings
  1222  			executeErr error
  1223  		)
  1224  		BeforeEach(func() {
  1225  			spaceGUID = "space-guid"
  1226  		})
  1227  
  1228  		JustBeforeEach(func() {
  1229  			warnings, executeErr = actor.DeleteOrphanedRoutes(spaceGUID)
  1230  		})
  1231  
  1232  		When("the cloud controller client succeeds", func() {
  1233  			BeforeEach(func() {
  1234  				fakeCloudControllerClient.DeleteOrphanedRoutesReturns(
  1235  					ccv3.JobURL("job"),
  1236  					ccv3.Warnings{"delete-orphaned-routes-warning"},
  1237  					nil,
  1238  				)
  1239  			})
  1240  
  1241  			It("deletes orphaned routes", func() {
  1242  				Expect(fakeCloudControllerClient.DeleteOrphanedRoutesCallCount()).To(Equal(1))
  1243  				Expect(fakeCloudControllerClient.DeleteOrphanedRoutesArgsForCall(0)).To(Equal(spaceGUID))
  1244  			})
  1245  
  1246  			When("polling the job succeeds", func() {
  1247  				BeforeEach(func() {
  1248  					fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"poll-job-warning"}, nil)
  1249  				})
  1250  				It("returns the error and warnings", func() {
  1251  					Expect(executeErr).ToNot(HaveOccurred())
  1252  					Expect(warnings).To(ConsistOf("delete-orphaned-routes-warning", "poll-job-warning"))
  1253  
  1254  					Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
  1255  					Expect(fakeCloudControllerClient.PollJobArgsForCall(0)).To(Equal(ccv3.JobURL("job")))
  1256  				})
  1257  			})
  1258  
  1259  			When("polling the job errors", func() {
  1260  				BeforeEach(func() {
  1261  					fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"poll-job-warning"}, errors.New("poll-error"))
  1262  				})
  1263  				It("returns the error and warnings", func() {
  1264  					Expect(executeErr).To(MatchError("poll-error"))
  1265  					Expect(warnings).To(ConsistOf("delete-orphaned-routes-warning", "poll-job-warning"))
  1266  
  1267  					Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
  1268  					Expect(fakeCloudControllerClient.PollJobArgsForCall(0)).To(Equal(ccv3.JobURL("job")))
  1269  				})
  1270  			})
  1271  		})
  1272  
  1273  		When("the cloud controller client error", func() {
  1274  			BeforeEach(func() {
  1275  				fakeCloudControllerClient.DeleteOrphanedRoutesReturns(
  1276  					ccv3.JobURL(""),
  1277  					ccv3.Warnings{"delete-orphaned-routes-warning"},
  1278  					errors.New("orphaned-error"),
  1279  				)
  1280  			})
  1281  
  1282  			It("returns the error and warnings", func() {
  1283  				Expect(executeErr).To(MatchError("orphaned-error"))
  1284  				Expect(warnings).To(ConsistOf("delete-orphaned-routes-warning"))
  1285  
  1286  				Expect(fakeCloudControllerClient.DeleteOrphanedRoutesCallCount()).To(Equal(1))
  1287  				Expect(fakeCloudControllerClient.DeleteOrphanedRoutesArgsForCall(0)).To(Equal(spaceGUID))
  1288  
  1289  				Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(0))
  1290  			})
  1291  		})
  1292  	})
  1293  
  1294  	Describe("GetApplicationRoutes", func() {
  1295  		var (
  1296  			appGUID string
  1297  
  1298  			routes     []Route
  1299  			warnings   Warnings
  1300  			executeErr error
  1301  		)
  1302  
  1303  		BeforeEach(func() {
  1304  			appGUID = "some-app-guid"
  1305  		})
  1306  
  1307  		JustBeforeEach(func() {
  1308  			routes, warnings, executeErr = actor.GetApplicationRoutes(appGUID)
  1309  		})
  1310  
  1311  		When("getting routes fails", func() {
  1312  			BeforeEach(func() {
  1313  				fakeCloudControllerClient.GetApplicationRoutesReturns(
  1314  					[]ccv3.Route{},
  1315  					ccv3.Warnings{"get-application-routes-warning"},
  1316  					errors.New("application-routes-error"),
  1317  				)
  1318  			})
  1319  
  1320  			It("returns the warnings and error", func() {
  1321  				Expect(executeErr).To(MatchError("application-routes-error"))
  1322  				Expect(warnings).To(ConsistOf("get-application-routes-warning"))
  1323  
  1324  				Expect(fakeCloudControllerClient.GetApplicationRoutesCallCount()).To(Equal(1))
  1325  				Expect(fakeCloudControllerClient.GetApplicationRoutesArgsForCall(0)).To(Equal(appGUID))
  1326  			})
  1327  		})
  1328  
  1329  		When("getting routes succeeds", func() {
  1330  			BeforeEach(func() {
  1331  				fakeCloudControllerClient.GetSpacesReturns(
  1332  					[]ccv3.Space{
  1333  						{
  1334  							GUID: "routes-space-guid",
  1335  							Name: "space-name",
  1336  						},
  1337  					},
  1338  					ccv3.Warnings{"get-spaces-warning"},
  1339  					nil,
  1340  				)
  1341  				fakeCloudControllerClient.GetApplicationRoutesReturns(
  1342  					[]ccv3.Route{
  1343  						{
  1344  							GUID:       "some-route-guid",
  1345  							URL:        "some-url.sh",
  1346  							SpaceGUID:  "routes-space-guid",
  1347  							DomainGUID: "routes-domain-guid",
  1348  						},
  1349  					},
  1350  					ccv3.Warnings{"get-application-routes-warning"},
  1351  					nil,
  1352  				)
  1353  			})
  1354  
  1355  			It("returns the warnings and routes", func() {
  1356  				Expect(executeErr).NotTo(HaveOccurred())
  1357  				Expect(warnings).To(ConsistOf("get-spaces-warning", "get-application-routes-warning"))
  1358  
  1359  				Expect(fakeCloudControllerClient.GetApplicationRoutesCallCount()).To(Equal(1))
  1360  				Expect(fakeCloudControllerClient.GetApplicationRoutesArgsForCall(0)).To(Equal(appGUID))
  1361  
  1362  				Expect(routes).To(ConsistOf(
  1363  					Route{
  1364  						GUID:         "some-route-guid",
  1365  						URL:          "some-url.sh",
  1366  						SpaceGUID:    "routes-space-guid",
  1367  						DomainGUID:   "routes-domain-guid",
  1368  						SpaceName:    "space-name",
  1369  						DomainName:   "some-url.sh",
  1370  						Destinations: []RouteDestination{},
  1371  					},
  1372  				))
  1373  			})
  1374  
  1375  			When("no routes are returned", func() {
  1376  				BeforeEach(func() {
  1377  					fakeCloudControllerClient.GetApplicationRoutesReturns(
  1378  						[]ccv3.Route{},
  1379  						ccv3.Warnings{"get-application-routes-warning"},
  1380  						nil,
  1381  					)
  1382  				})
  1383  
  1384  				It("returns an empty list", func() {
  1385  					Expect(executeErr).NotTo(HaveOccurred())
  1386  					Expect(warnings).To(ConsistOf("get-application-routes-warning"))
  1387  					Expect(routes).To(HaveLen(0))
  1388  				})
  1389  			})
  1390  
  1391  			When("getting spaces fails", func() {
  1392  				var err = errors.New("failed to get spaces")
  1393  
  1394  				BeforeEach(func() {
  1395  					fakeCloudControllerClient.GetSpacesReturns(
  1396  						nil,
  1397  						ccv3.Warnings{"get-spaces-warning"},
  1398  						err,
  1399  					)
  1400  				})
  1401  
  1402  				It("returns the error and any warnings", func() {
  1403  					Expect(executeErr).To(Equal(err))
  1404  					Expect(warnings).To(ConsistOf("get-application-routes-warning", "get-spaces-warning"))
  1405  
  1406  					Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1))
  1407  					queries := fakeCloudControllerClient.GetSpacesArgsForCall(0)
  1408  					Expect(queries).To(ConsistOf(ccv3.Query{Key: ccv3.GUIDFilter, Values: []string{"routes-space-guid"}}))
  1409  				})
  1410  			})
  1411  		})
  1412  	})
  1413  })