mirror of https://github.com/dapr/go-sdk.git
new service with existing http mux (#52)
This commit is contained in:
parent
d6de57c71a
commit
79e0f554b0
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func TestBindingHandlerWithoutData(t *testing.T) {
|
||||
s := newService("")
|
||||
s := newServer("", nil)
|
||||
err := s.AddBindingInvocationHandler("/", func(ctx context.Context, in *common.BindingEvent) (out []byte, err error) {
|
||||
if in == nil {
|
||||
return nil, errors.New("nil input")
|
||||
|
|
@ -37,7 +37,7 @@ func TestBindingHandlerWithoutData(t *testing.T) {
|
|||
|
||||
func TestBindingHandlerWithData(t *testing.T) {
|
||||
data := `{"name": "test"}`
|
||||
s := newService("")
|
||||
s := newServer("", nil)
|
||||
err := s.AddBindingInvocationHandler("/", func(ctx context.Context, in *common.BindingEvent) (out []byte, err error) {
|
||||
if in == nil {
|
||||
return nil, errors.New("nil input")
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
func TestInvocationHandlerWithData(t *testing.T) {
|
||||
data := `{"name": "test", "data": hellow}`
|
||||
s := newService("")
|
||||
s := newServer("", nil)
|
||||
err := s.AddServiceInvocationHandler("/", func(ctx context.Context, in *common.InvocationEvent) (out *common.Content, err error) {
|
||||
if in == nil || in.Data == nil || in.ContentType == "" {
|
||||
err = errors.New("nil input")
|
||||
|
|
@ -44,7 +44,7 @@ func TestInvocationHandlerWithData(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInvocationHandlerWithoutInputData(t *testing.T) {
|
||||
s := newService("")
|
||||
s := newServer("", nil)
|
||||
err := s.AddServiceInvocationHandler("/", func(ctx context.Context, in *common.InvocationEvent) (out *common.Content, err error) {
|
||||
if in == nil || in.Data != nil {
|
||||
err = errors.New("nil input")
|
||||
|
|
@ -69,7 +69,7 @@ func TestInvocationHandlerWithoutInputData(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInvocationHandlerWithInvalidRoute(t *testing.T) {
|
||||
s := newService("")
|
||||
s := newServer("", nil)
|
||||
err := s.AddServiceInvocationHandler("/a", func(ctx context.Context, in *common.InvocationEvent) (out *common.Content, err error) {
|
||||
return nil, nil
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,13 +8,21 @@ import (
|
|||
|
||||
// NewService creates new Service
|
||||
func NewService(address string) common.Service {
|
||||
return newService(address)
|
||||
return newServer(address, nil)
|
||||
}
|
||||
|
||||
func newService(address string) *Server {
|
||||
// NewServiceWithMux creates new Service with existing http mux
|
||||
func NewServiceWithMux(address string, mux *http.ServeMux) common.Service {
|
||||
return newServer(address, mux)
|
||||
}
|
||||
|
||||
func newServer(address string, mux *http.ServeMux) *Server {
|
||||
if mux == nil {
|
||||
mux = http.NewServeMux()
|
||||
}
|
||||
return &Server{
|
||||
address: address,
|
||||
mux: http.NewServeMux(),
|
||||
mux: mux,
|
||||
topicSubscriptions: make([]*common.Subscription, 0),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ import (
|
|||
)
|
||||
|
||||
func TestStoppingUnstartedService(t *testing.T) {
|
||||
s := newService("")
|
||||
s := newServer("", nil)
|
||||
assert.NotNil(t, s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func TestEventHandler(t *testing.T) {
|
|||
"data" : "eyJtZXNzYWdlIjoiaGVsbG8ifQ=="
|
||||
}`
|
||||
|
||||
s := newService("")
|
||||
s := newServer("", nil)
|
||||
|
||||
sub := &common.Subscription{
|
||||
PubsubName: "messages",
|
||||
|
|
|
|||
Loading…
Reference in New Issue