@@ -251,6 +251,140 @@ var _ = Describe("Service App Binding Action", func() {
251251 })
252252 })
253253
254+ Describe ("ListAppBindings" , func () {
255+ const (
256+ appName = "fake-app-name"
257+ appGUID = "fake-app-guid"
258+ spaceGUID = "fake-space-guid"
259+ bindingGUID = "fake-binding-guid"
260+ )
261+
262+ var (
263+ params ListAppBindingParams
264+ warnings Warnings
265+ executionError error
266+ serviceCredentialBindings []resources.ServiceCredentialBinding
267+ )
268+
269+ BeforeEach (func () {
270+ fakeCloudControllerClient .GetApplicationByNameAndSpaceReturns (
271+ resources.Application {
272+ GUID : appGUID ,
273+ Name : appName ,
274+ },
275+ ccv3.Warnings {"get app warning" },
276+ nil ,
277+ )
278+
279+ fakeCloudControllerClient .GetServiceCredentialBindingsReturns (
280+ []resources.ServiceCredentialBinding {
281+ {GUID : bindingGUID },
282+ },
283+ ccv3.Warnings {"get bindings warning" },
284+ nil ,
285+ )
286+
287+ params = ListAppBindingParams {
288+ SpaceGUID : "fake-space-guid" ,
289+ AppName : "fake-app-name" ,
290+ }
291+ })
292+
293+ JustBeforeEach (func () {
294+ serviceCredentialBindings , warnings , executionError = actor .ListAppBindings (params )
295+ })
296+
297+ It ("returns an event stream, warning, and no errors" , func () {
298+ Expect (executionError ).NotTo (HaveOccurred ())
299+
300+ Expect (warnings ).To (ConsistOf (Warnings {
301+ "get app warning" ,
302+ "get bindings warning" ,
303+ }))
304+
305+ Expect (serviceCredentialBindings ).To (Equal ([]resources.ServiceCredentialBinding {{GUID : bindingGUID }}))
306+ })
307+
308+ Describe ("app lookup" , func () {
309+ It ("makes the correct call" , func () {
310+ Expect (fakeCloudControllerClient .GetApplicationByNameAndSpaceCallCount ()).To (Equal (1 ))
311+ actualAppName , actualSpaceGUID := fakeCloudControllerClient .GetApplicationByNameAndSpaceArgsForCall (0 )
312+ Expect (actualAppName ).To (Equal (appName ))
313+ Expect (actualSpaceGUID ).To (Equal (spaceGUID ))
314+ })
315+
316+ When ("not found" , func () {
317+ BeforeEach (func () {
318+ fakeCloudControllerClient .GetApplicationByNameAndSpaceReturns (
319+ resources.Application {},
320+ ccv3.Warnings {"get app warning" },
321+ ccerror.ApplicationNotFoundError {Name : appName },
322+ )
323+ })
324+
325+ It ("returns the error and warning" , func () {
326+ Expect (warnings ).To (ContainElement ("get app warning" ))
327+ Expect (executionError ).To (MatchError (actionerror.ApplicationNotFoundError {Name : appName }))
328+ })
329+ })
330+
331+ When ("fails" , func () {
332+ BeforeEach (func () {
333+ fakeCloudControllerClient .GetApplicationByNameAndSpaceReturns (
334+ resources.Application {},
335+ ccv3.Warnings {"get app warning" },
336+ errors .New ("boom" ),
337+ )
338+ })
339+
340+ It ("returns the error and warning" , func () {
341+ Expect (warnings ).To (ContainElement ("get app warning" ))
342+ Expect (executionError ).To (MatchError ("boom" ))
343+ })
344+ })
345+ })
346+
347+ Describe ("binding lookup" , func () {
348+ It ("makes the correct call" , func () {
349+ Expect (fakeCloudControllerClient .GetServiceCredentialBindingsCallCount ()).To (Equal (1 ))
350+ Expect (fakeCloudControllerClient .GetServiceCredentialBindingsArgsForCall (0 )).To (ConsistOf (
351+ ccv3.Query {Key : ccv3 .TypeFilter , Values : []string {"app" }},
352+ ccv3.Query {Key : ccv3 .AppGUIDFilter , Values : []string {appGUID }},
353+ ))
354+ })
355+
356+ When ("there are no bindings" , func () {
357+ BeforeEach (func () {
358+ fakeCloudControllerClient .GetServiceCredentialBindingsReturns (
359+ []resources.ServiceCredentialBinding {},
360+ ccv3.Warnings {"get bindings warning" },
361+ nil ,
362+ )
363+ })
364+
365+ It ("returns an empty list" , func () {
366+ Expect (warnings ).To (ContainElement ("get bindings warning" ))
367+ Expect (serviceCredentialBindings ).To (Equal ([]resources.ServiceCredentialBinding {}))
368+ })
369+ })
370+
371+ When ("fails" , func () {
372+ BeforeEach (func () {
373+ fakeCloudControllerClient .GetServiceCredentialBindingsReturns (
374+ []resources.ServiceCredentialBinding {},
375+ ccv3.Warnings {"get binding warning" },
376+ errors .New ("boom" ),
377+ )
378+ })
379+
380+ It ("returns the error and warning" , func () {
381+ Expect (warnings ).To (ContainElement ("get binding warning" ))
382+ Expect (executionError ).To (MatchError ("boom" ))
383+ })
384+ })
385+ })
386+ })
387+
254388 Describe ("ListServiceAppBindings" , func () {
255389 const (
256390 serviceInstanceName = "fake-service-instance-name"
0 commit comments