diff --git a/pkg/brokerapi/fakeserver/fake_broker_server.go b/pkg/brokerapi/fakeserver/fake_broker_server.go index c1961c20177..8259bebca2c 100644 --- a/pkg/brokerapi/fakeserver/fake_broker_server.go +++ b/pkg/brokerapi/fakeserver/fake_broker_server.go @@ -96,6 +96,8 @@ func NewFakeBrokerServer() *FakeBrokerServer { } +// ProvisionReaction represents a reaction that the fake server should make to +// a provision request. type ProvisionReaction struct { Status int Response *brokerapi.CreateServiceInstanceResponse @@ -209,12 +211,11 @@ func (f *FakeBrokerServer) lastOperationHandler(w http.ResponseWriter, r *http.R State: brokerapi.StateInProgress, }) } else { - // TODO: add instance to list of active instances - // if activeProvision.AsyncResult == brokerapi.StateSucceeded - // f.ActiveInstances = + f.ActiveInstances[id] = f.OriginatingProvisionRequests[id] delete(f.ActiveProvisions, req.Operation) + delete(f.OriginatingProvisionRequests, id) - glog.Infof("(provision) Returning response status %v to last_operation request %v", activeProvision.AsyncResult, req.Operation) + glog.Infof("Returning response status %v to last_operation request %v", activeProvision.AsyncResult, req.Operation) util.WriteResponse(w, http.StatusOK, brokerapi.LastOperationResponse{ State: activeProvision.AsyncResult, @@ -318,8 +319,14 @@ func (f *FakeBrokerServer) provisionHandler(w http.ResponseWriter, r *http.Reque return } - // record the state of the async reaction - f.ActiveProvisions[reaction.Operation] = reaction + // record the state of the async reaction, if it is destined to succeed + if reaction.Status == http.StatusAccepted { + f.ActiveProvisions[reaction.Operation] = reaction + } + + if reaction.AsyncResult == brokerapi.StateSucceeded { + f.OriginatingProvisionRequests[id] = *req + } util.WriteResponse(w, reaction.Status, &brokerapi.CreateServiceInstanceResponse{ Operation: reaction.Operation, diff --git a/pkg/brokerapi/openservicebroker/open_service_broker_client_test.go b/pkg/brokerapi/openservicebroker/open_service_broker_client_test.go index 323ace50025..72058e7c2ca 100644 --- a/pkg/brokerapi/openservicebroker/open_service_broker_client_test.go +++ b/pkg/brokerapi/openservicebroker/open_service_broker_client_test.go @@ -232,14 +232,12 @@ func TestDeprovisionInstanceAcceptedSuccessAsynchronous(t *testing.T) { defer fbs.Stop() fbs.ProvisionReactions[testServiceInstanceID] = fakeserver.ProvisionReaction{ - Status: http.StatusCreated, - } - - c := NewClient(testBrokerName, url, "", "") - if _, err := c.CreateServiceInstance(testServiceInstanceID, &brokerapi.CreateServiceInstanceRequest{}); err != nil { - t.Fatal(err.Error()) + Status: http.StatusAccepted, + Async: true, + Operation: "12345", + Polls: 2, + AsyncResult: brokerapi.StateSucceeded, } - fbs.DeprovisionReactions[testServiceInstanceID] = fakeserver.DeprovisionReaction{ Status: http.StatusAccepted, Async: true, @@ -248,12 +246,21 @@ func TestDeprovisionInstanceAcceptedSuccessAsynchronous(t *testing.T) { AsyncResult: brokerapi.StateSucceeded, } - deleteReq := brokerapi.DeleteServiceInstanceRequest{ + req := brokerapi.CreateServiceInstanceRequest{ AcceptsIncomplete: true, ServiceID: "014-01840", PlanID: "54331", } + c := NewClient(testBrokerName, url, "", "") + if _, err := c.CreateServiceInstance(testServiceInstanceID, &req); err != nil { + t.Fatal(err.Error()) + } + deleteReq := brokerapi.DeleteServiceInstanceRequest{ + AcceptsIncomplete: true, + ServiceID: "014-01840", + PlanID: "54331", + } if err := c.DeleteServiceInstance(testServiceInstanceID, &deleteReq); err != nil { t.Fatal(err.Error()) }