@@ -182,6 +182,11 @@ var _ = Describe("Service Broker API", func() {
182182 makeRequest ("GET" , "/v2/service_instances/instance-id/last_operation" , "{}" )
183183 Expect (fakeServiceBroker .ReceivedContext ).To (BeTrue ())
184184 })
185+
186+ Specify ("a get instance operation endpoint which passes the request context to the broker" , func () {
187+ makeRequest ("GET" , "/v2/service_instances/instance-id" , "{}" )
188+ Expect (fakeServiceBroker .ReceivedContext ).To (BeTrue ())
189+ })
185190 })
186191
187192 Describe ("authentication" , func () {
@@ -297,6 +302,19 @@ var _ = Describe("Service Broker API", func() {
297302 })
298303
299304 Describe ("instance lifecycle endpoint" , func () {
305+ makeGetInstanceRequest := func (instanceID string ) * testflight.Response {
306+ response := & testflight.Response {}
307+ testflight .WithServer (brokerAPI , func (r * testflight.Requester ) {
308+ path := fmt .Sprintf ("/v2/service_instances/%s" , instanceID )
309+ request , err := http .NewRequest ("GET" , path , strings .NewReader ("" ))
310+ Expect (err ).NotTo (HaveOccurred ())
311+ request .Header .Add ("X-Broker-API-Version" , apiVersion )
312+ request .SetBasicAuth ("username" , "password" )
313+ response = r .Do (request )
314+ })
315+ return response
316+ }
317+
300318 makeInstanceDeprovisioningRequestFull := func (instanceID , serviceID , planID , queryString string ) * testflight.Response {
301319 response := & testflight.Response {}
302320 testflight .WithServer (brokerAPI , func (r * testflight.Requester ) {
@@ -348,6 +366,15 @@ var _ = Describe("Service Broker API", func() {
348366 Expect (fakeServiceBroker .ProvisionedInstanceIDs ).To (ContainElement (instanceID ))
349367 })
350368
369+ It ("calls GetInstance on the service broker with the instance id" , func () {
370+ makeInstanceProvisioningRequest (instanceID , provisionDetails , "" )
371+ Expect (fakeServiceBroker .ProvisionedInstanceIDs ).To (ContainElement (instanceID ))
372+ fakeServiceBroker .DashboardURL = "https://example.com/dashboard/some-instance"
373+ resp := makeGetInstanceRequest (instanceID )
374+ Expect (fakeServiceBroker .GetInstanceIDs ).To (ContainElement (instanceID ))
375+ Expect (resp .Body ).To (MatchJSON (fixture ("get_instance.json" )))
376+ })
377+
351378 Context ("when the broker returns some operation data" , func () {
352379 BeforeEach (func () {
353380 fakeServiceBroker = & fakes.FakeServiceBroker {
@@ -1218,6 +1245,60 @@ var _ = Describe("Service Broker API", func() {
12181245 })
12191246 })
12201247 })
1248+
1249+ Describe ("getting instance" , func () {
1250+ It ("returns the appropriate status code when it fails with a known error" , func () {
1251+ fakeServiceBroker .GetInstanceError = brokerapi .NewFailureResponse (errors .New ("some error" ), http .StatusUnprocessableEntity , "fire" )
1252+
1253+ response := makeGetInstanceRequest ("instance-id" )
1254+
1255+ Expect (response .StatusCode ).To (Equal (http .StatusUnprocessableEntity ))
1256+ Expect (lastLogLine ().Message ).To (ContainSubstring ("broker-api.getInstance.fire" ))
1257+ Expect (lastLogLine ().Data ["error" ]).To (ContainSubstring ("some error" ))
1258+ })
1259+
1260+ It ("returns 500 when it fails with an unknown error" , func () {
1261+ fakeServiceBroker .GetInstanceError = errors .New ("failed to get instance" )
1262+
1263+ response := makeGetInstanceRequest ("instance-id" )
1264+
1265+ Expect (response .StatusCode ).To (Equal (500 ))
1266+ Expect (lastLogLine ().Message ).To (ContainSubstring ("broker-api.getInstance.unknown-error" ))
1267+ Expect (lastLogLine ().Data ["error" ]).To (ContainSubstring ("failed to get instance" ))
1268+ })
1269+
1270+ Context ("the request is malformed" , func () {
1271+ It ("missing header X-Broker-API-Version" , func () {
1272+ apiVersion = ""
1273+ response := makeGetInstanceRequest ("instance-id" )
1274+ Expect (response .StatusCode ).To (Equal (412 ))
1275+ Expect (lastLogLine ().Message ).To (ContainSubstring (".getInstance.broker-api-version-invalid" ))
1276+ Expect (lastLogLine ().Data ["error" ]).To (ContainSubstring ("X-Broker-API-Version Header not set" ))
1277+ })
1278+
1279+ It ("has wrong version of API" , func () {
1280+ apiVersion = "1.1"
1281+ response := makeGetInstanceRequest ("instance-id" )
1282+ Expect (response .StatusCode ).To (Equal (412 ))
1283+ Expect (lastLogLine ().Message ).To (ContainSubstring (".getInstance.broker-api-version-invalid" ))
1284+ Expect (lastLogLine ().Data ["error" ]).To (ContainSubstring ("X-Broker-API-Version Header must be 2.x" ))
1285+ })
1286+
1287+ It ("is using api version < 2.14" , func () {
1288+ apiVersion = "2.13"
1289+ response := makeGetInstanceRequest ("instance-id" )
1290+ Expect (response .StatusCode ).To (Equal (412 ))
1291+
1292+ Expect (lastLogLine ().Message ).To (ContainSubstring (".getInstance.broker-api-version-invalid" ))
1293+ Expect (lastLogLine ().Data ["error" ]).To (ContainSubstring ("get instance endpoint only supported starting with OSB version 2.14" ))
1294+ })
1295+
1296+ It ("missing instance-id" , func () {
1297+ response := makeGetInstanceRequest ("" )
1298+ Expect (response .StatusCode ).To (Equal (404 ))
1299+ })
1300+ })
1301+ })
12211302 })
12221303
12231304 Describe ("binding lifecycle endpoint" , func () {
0 commit comments