func TestInbox(t *testing.T) { Convey("Should call actor.handleRequest", t, func() { var called bool handleRequest = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message) { called = true return } var requestWrapper messages.RequestWrapper requestWrapper.Res = "/" responseChannel := make(chan messages.Message) requestWrapper.Listener = responseChannel var actor Actor actor.class = "someclass" actor.res = "/" actor.Inbox = make(chan messages.RequestWrapper) go actor.Run() actor.Inbox <- requestWrapper response := <-responseChannel So(response, ShouldNotBeNil) So(called, ShouldBeTrue) }) Convey("Should forward message to a child actor", t, func() { parentRes := "/users" childRes := "/users/123" var calledOnParent bool var calledOnChild bool handleRequest = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message) { if strings.EqualFold(a.res, parentRes) { calledOnParent = true } if strings.EqualFold(a.res, childRes) { calledOnChild = true } return } var requestWrapper messages.RequestWrapper requestWrapper.Res = childRes responseChannel := make(chan messages.Message) requestWrapper.Listener = responseChannel CreateActor = func(res string, level int, parentInbox chan messages.RequestWrapper) (a Actor) { a.res = childRes a.level = 2 a.Inbox = make(chan messages.RequestWrapper) return } var actor Actor actor.res = parentRes actor.level = 1 actor.children = make(map[string]Actor) actor.Inbox = make(chan messages.RequestWrapper) go actor.Run() actor.Inbox <- requestWrapper response := <-responseChannel So(response, ShouldNotBeNil) So(calledOnParent, ShouldBeFalse) So(calledOnChild, ShouldBeTrue) }) }