Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding library response types #27

Merged
merged 3 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkg/broker/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Interface interface {
// For more information, see:
//
// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#catalog-management
GetCatalog(c *RequestContext) (*osb.CatalogResponse, error)
GetCatalog(c *RequestContext) (*CatalogResponse, error)
// Provision encapsulates the business logic for a provision operation and
// returns a osb.ProvisionResponse or an error. Provisioning creates a new
// instance of a particular service.
Expand All @@ -53,7 +53,7 @@ type Interface interface {
// For more information, see:
//
// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#provisioning
Provision(request *osb.ProvisionRequest, c *RequestContext) (*osb.ProvisionResponse, error)
Provision(request *osb.ProvisionRequest, c *RequestContext) (*ProvisionResponse, error)
// Deprovision encapsulates the business logic for a deprovision operation
// and returns a osb.DeprovisionResponse or an error. Deprovisioning deletes
// an instance of a service and releases the resources associated with it.
Expand All @@ -74,7 +74,7 @@ type Interface interface {
// For more information, see:
//
// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#deprovisioning
Deprovision(request *osb.DeprovisionRequest, c *RequestContext) (*osb.DeprovisionResponse, error)
Deprovision(request *osb.DeprovisionRequest, c *RequestContext) (*DeprovisionResponse, error)
// LastOperation encapsulates the business logic for a last operation
// request and returns a osb.LastOperationResponse or an error.
// LastOperation is called when a platform checks the status of an ongoing
Expand All @@ -96,7 +96,7 @@ type Interface interface {
// For more information, see:
//
// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#polling-last-operation
LastOperation(request *osb.LastOperationRequest, c *RequestContext) (*osb.LastOperationResponse, error)
LastOperation(request *osb.LastOperationRequest, c *RequestContext) (*LastOperationResponse, error)
// Bind encapsulates the business logic for a bind operation and returns a
// osb.BindResponse or an error. Binding creates a new set of credentials for
// a consumer to use an instance of a service. Not all services are
Expand All @@ -119,7 +119,7 @@ type Interface interface {
// For more information, see:
//
// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#binding
Bind(request *osb.BindRequest, c *RequestContext) (*osb.BindResponse, error)
Bind(request *osb.BindRequest, c *RequestContext) (*BindResponse, error)
// Unbind encapsulates the business logic for an unbind operation and
// returns a osb.UnbindResponse or an error. Unbind deletes a binding and the
// resources associated with it.
Expand All @@ -139,7 +139,7 @@ type Interface interface {
// For more information, see:
//
// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#unbinding
Unbind(request *osb.UnbindRequest, c *RequestContext) (*osb.UnbindResponse, error)
Unbind(request *osb.UnbindRequest, c *RequestContext) (*UnbindResponse, error)
// Update encapsulates the business logic for an update operation and
// returns a osb.UpdateInstanceResponse or an error. Update updates the
// instance.
Expand All @@ -159,7 +159,7 @@ type Interface interface {
// For more information, see:
//
// https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#updating-a-service-instance
Update(request *osb.UpdateInstanceRequest, c *RequestContext) (*osb.UpdateInstanceResponse, error)
Update(request *osb.UpdateInstanceRequest, c *RequestContext) (*UpdateInstanceResponse, error)
}

// RequestContext encapsulates the following parameters:
Expand Down
38 changes: 38 additions & 0 deletions pkg/broker/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package broker

import osb "github.com/pmorie/go-open-service-broker-client/v2"

// CatalogResponse is sent as the response to a catalog requests.
type CatalogResponse struct {
osb.CatalogResponse
}

// ProvisionResponse is sent as the response to a provision call.
type ProvisionResponse struct {
osb.ProvisionResponse
}

// UpdateInstanceResponse is sent as the response to a update call.
type UpdateInstanceResponse struct {
osb.UpdateInstanceResponse
}

// DeprovisionResponse is sent as the response to a deprovision call.
type DeprovisionResponse struct {
osb.DeprovisionResponse
}

// LastOperationResponse is sent as the response to a last operation call.
type LastOperationResponse struct {
osb.LastOperationResponse
}

// BindResponse is sent as the response to a bind call.
type BindResponse struct {
osb.BindResponse
}

// UnbindResponse is sent as the response to a bind call.
type UnbindResponse struct {
osb.UnbindResponse
}
14 changes: 7 additions & 7 deletions pkg/server/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestBind(t *testing.T) {
cases := []struct {
name string
validateFunc func(string) error
bindFunc func(req *osb.BindRequest, c *broker.RequestContext) (*osb.BindResponse, error)
bindFunc func(req *osb.BindRequest, c *broker.RequestContext) (*broker.BindResponse, error)
response *osb.BindResponse
err error
}{
Expand All @@ -36,7 +36,7 @@ func TestBind(t *testing.T) {
},
{
name: "bind returns errors.New",
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*osb.BindResponse, error) {
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*broker.BindResponse, error) {
return nil, errors.New("oops")
},
err: osb.HTTPStatusCodeError{
Expand All @@ -46,7 +46,7 @@ func TestBind(t *testing.T) {
},
{
name: "bind returns osb.HTTPStatusCodeError",
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*osb.BindResponse, error) {
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*broker.BindResponse, error) {
return nil, osb.HTTPStatusCodeError{
StatusCode: http.StatusBadGateway,
Description: strPtr("custom error"),
Expand All @@ -59,17 +59,17 @@ func TestBind(t *testing.T) {
},
{
name: "OK",
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*osb.BindResponse, error) {
return &osb.BindResponse{}, nil
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*broker.BindResponse, error) {
return &broker.BindResponse{}, nil
},
response: &osb.BindResponse{},
},
{
name: "bind check originating origin identity is passed",
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*osb.BindResponse, error) {
bindFunc: func(req *osb.BindRequest, c *broker.RequestContext) (*broker.BindResponse, error) {
if req.OriginatingIdentity != nil {

return &osb.BindResponse{}, nil
return &broker.BindResponse{}, nil
}
return nil, fmt.Errorf("oops")
},
Expand Down
21 changes: 11 additions & 10 deletions pkg/server/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ import (
)

func TestGetCatalog(t *testing.T) {
okResponse := &osb.CatalogResponse{Services: []osb.Service{
{
Name: "foo",
},
}}
okResponse := &broker.CatalogResponse{
CatalogResponse: osb.CatalogResponse{
Services: []osb.Service{
{
Name: "foo",
},
}}}

cases := []struct {
name string
validateFunc func(string) error
catalogFunc func(c *broker.RequestContext) (*osb.CatalogResponse, error)
response *osb.CatalogResponse
catalogFunc func(c *broker.RequestContext) (*broker.CatalogResponse, error)
response *broker.CatalogResponse
err error
}{
{
name: "OK",
catalogFunc: func(c *broker.RequestContext) (*osb.CatalogResponse, error) {
catalogFunc: func(c *broker.RequestContext) (*broker.CatalogResponse, error) {
return okResponse, nil
},
response: okResponse,
Expand Down Expand Up @@ -93,8 +95,7 @@ func TestGetCatalog(t *testing.T) {
t.Error(err)
return
}

if e, a := tc.response, actualResponse; !reflect.DeepEqual(e, a) {
if e, a := &tc.response.CatalogResponse, actualResponse; !reflect.DeepEqual(e, a) {
t.Errorf("Unexpected response\n\nExpected: %#+v\n\nGot: %#+v", e, a)
}
})
Expand Down
52 changes: 30 additions & 22 deletions pkg/server/deprovision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func TestDeprovision(t *testing.T) {
cases := []struct {
name string
validateFunc func(string) error
deprovisionFunc func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error)
response *osb.DeprovisionResponse
deprovisionFunc func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error)
response *broker.DeprovisionResponse
err error
}{
{
Expand All @@ -36,7 +36,7 @@ func TestDeprovision(t *testing.T) {
},
{
name: "returns errors.New",
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error) {
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error) {
return nil, errors.New("oops")
},
err: osb.HTTPStatusCodeError{
Expand All @@ -46,17 +46,17 @@ func TestDeprovision(t *testing.T) {
},
{
name: "validate incoming parameters",
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error) {
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error) {
if req.PlanID == "" {
return nil, errors.New("deprovision request missing plan_id query parameter")
}
return &osb.DeprovisionResponse{}, nil
return &broker.DeprovisionResponse{}, nil
},
response: &osb.DeprovisionResponse{},
response: &broker.DeprovisionResponse{},
},
{
name: "returns osb.HTTPStatusCodeError",
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error) {
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error) {
return nil, osb.HTTPStatusCodeError{
StatusCode: http.StatusBadGateway,
Description: strPtr("custom error"),
Expand All @@ -69,34 +69,42 @@ func TestDeprovision(t *testing.T) {
},
{
name: "returns sync",
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error) {
return &osb.DeprovisionResponse{}, nil
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error) {
return &broker.DeprovisionResponse{}, nil
},
response: &osb.DeprovisionResponse{},
response: &broker.DeprovisionResponse{},
},
{
name: "returns async",
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error) {
return &osb.DeprovisionResponse{
Async: true,
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error) {
return &broker.DeprovisionResponse{
DeprovisionResponse: osb.DeprovisionResponse{
Async: true,
},
}, nil
},
response: &osb.DeprovisionResponse{
Async: true,
response: &broker.DeprovisionResponse{
DeprovisionResponse: osb.DeprovisionResponse{
Async: true,
},
},
},
{
name: "check originating origin identity is passed",
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error) {
deprovisionFunc: func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error) {
if req.OriginatingIdentity != nil {
return &osb.DeprovisionResponse{
Async: true,
return &broker.DeprovisionResponse{
DeprovisionResponse: osb.DeprovisionResponse{
Async: true,
},
}, nil
}
return nil, fmt.Errorf("ops")
},
response: &osb.DeprovisionResponse{
Async: true,
response: &broker.DeprovisionResponse{
DeprovisionResponse: osb.DeprovisionResponse{
Async: true,
},
},
},
}
Expand All @@ -123,7 +131,7 @@ func TestDeprovision(t *testing.T) {
}

// establish that the request we got was the request we sent
deprovisionFunc := func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*osb.DeprovisionResponse, error) {
deprovisionFunc := func(req *osb.DeprovisionRequest, c *broker.RequestContext) (*broker.DeprovisionResponse, error) {
if !reflect.DeepEqual(request, req) {
t.Errorf("unexpected request; expected %v, got %v", request, req)
}
Expand Down Expand Up @@ -164,7 +172,7 @@ func TestDeprovision(t *testing.T) {
return
}

if e, a := tc.response, actualResponse; !reflect.DeepEqual(e, a) {
if e, a := &tc.response.DeprovisionResponse, actualResponse; !reflect.DeepEqual(e, a) {
t.Errorf("Unexpected response\n\nExpected: %#+v\n\nGot: %#+v", e, a)
}
})
Expand Down
25 changes: 14 additions & 11 deletions pkg/server/last_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func TestLastOperation(t *testing.T) {
cases := []struct {
name string
validateFunc func(string) error
lastOpFunc func(req *osb.LastOperationRequest, c *broker.RequestContext) (*osb.LastOperationResponse, error)
response *osb.LastOperationResponse
lastOpFunc func(req *osb.LastOperationRequest, c *broker.RequestContext) (*broker.LastOperationResponse, error)
response *broker.LastOperationResponse
err error
}{
{
Expand All @@ -35,7 +35,7 @@ func TestLastOperation(t *testing.T) {
},
{
name: "lastOperation returns errors.New",
lastOpFunc: func(req *osb.LastOperationRequest, c *broker.RequestContext) (*osb.LastOperationResponse, error) {
lastOpFunc: func(req *osb.LastOperationRequest, c *broker.RequestContext) (*broker.LastOperationResponse, error) {
return nil, errors.New("oops")
},
err: osb.HTTPStatusCodeError{
Expand All @@ -45,7 +45,7 @@ func TestLastOperation(t *testing.T) {
},
{
name: "lastOperation returns osb.HTTPStatusCodeError",
lastOpFunc: func(req *osb.LastOperationRequest, c *broker.RequestContext) (*osb.LastOperationResponse, error) {
lastOpFunc: func(req *osb.LastOperationRequest, c *broker.RequestContext) (*broker.LastOperationResponse, error) {
return nil, osb.HTTPStatusCodeError{
StatusCode: http.StatusBadGateway,
Description: strPtr("custom error"),
Expand All @@ -58,13 +58,16 @@ func TestLastOperation(t *testing.T) {
},
{
name: "OK",
lastOpFunc: func(req *osb.LastOperationRequest, c *broker.RequestContext) (*osb.LastOperationResponse, error) {
return &osb.LastOperationResponse{
State: osb.StateSucceeded,
}, nil
lastOpFunc: func(req *osb.LastOperationRequest, c *broker.RequestContext) (*broker.LastOperationResponse, error) {
return &broker.LastOperationResponse{
LastOperationResponse: osb.LastOperationResponse{
State: osb.StateSucceeded,
}}, nil
},
response: &osb.LastOperationResponse{
State: osb.StateSucceeded,
response: &broker.LastOperationResponse{
LastOperationResponse: osb.LastOperationResponse{
State: osb.StateSucceeded,
},
},
},
}
Expand Down Expand Up @@ -117,7 +120,7 @@ func TestLastOperation(t *testing.T) {
return
}

if e, a := tc.response, actualResponse; !reflect.DeepEqual(e, a) {
if e, a := &tc.response.LastOperationResponse, actualResponse; !reflect.DeepEqual(e, a) {
t.Errorf("Unexpected response\n\nExpected: %#+v\n\nGot: %#+v", e, a)
}
})
Expand Down
Loading