diff --git a/actions/http_server.go b/actions/http_server.go index 6f387e8..3fb761c 100644 --- a/actions/http_server.go +++ b/actions/http_server.go @@ -48,6 +48,9 @@ func (hs HttpServer) Run(c Context) error { for w := 0; w < c.Concurrency(); w++ { go writer(jobs, c) } + handler.Get("/_check", func(ctx http.GetContext) { + ctx.SendJson("OK") + }) handler.Get("/stream/:id", func(ctx http.GetContext) { stream := ctx.GetSegment("id") action := ReadEvents{Stream: stream} diff --git a/actions_test.go b/actions_test.go index 8237fea..a13b394 100644 --- a/actions_test.go +++ b/actions_test.go @@ -7,6 +7,7 @@ import ( "io" "io/ioutil" "net/http" + "time" . "github.com/scoiatael/archai" "github.com/scoiatael/archai/actions" @@ -54,6 +55,7 @@ var _ = Describe("Actions", func() { }) JustBeforeEach(func() { go action.Run(config) + time.Sleep(10 * time.Millisecond) address = fmt.Sprintf("http://127.0.0.1:%d", action.Port) }) @@ -87,8 +89,9 @@ var _ = Describe("Actions", func() { event.Run(config) }) - It("allows reading events", func() { - resp, err := http.Get(address) + + get := func(query string) interface{} { + resp, err := http.Get(address + query) Expect(err).NotTo(HaveOccurred()) body, err := ioutil.ReadAll(resp.Body) @@ -96,7 +99,19 @@ var _ = Describe("Actions", func() { js := make(map[string]interface{}) err = json.Unmarshal(body, &js) Expect(err).NotTo(HaveOccurred()) - Expect(js["results"]).NotTo(BeEmpty()) + return js["results"] + } + + It("allows reading events", func() { + results := get("") + Expect(results).NotTo(BeEmpty()) + Expect(results).To(HaveLen(1)) + }) + It("allows reading events with cursor", func() { + cursor := get("").([]interface{})[0].(map[string]interface{})["ID"].(string) + + results := get("?cursor=" + cursor) + Expect(results).To(BeEmpty()) }) }) }) diff --git a/http/iris.go b/http/iris.go index 218e464..259d0b2 100644 --- a/http/iris.go +++ b/http/iris.go @@ -31,11 +31,11 @@ type IrisGetContext struct { } func (hc IrisHttpContext) StringParam(index string) string { - return hc.Param(index) + return hc.URLParam(index) } func (hc IrisHttpContext) IntParam(index string, def int) int { - val, err := hc.ParamInt(index) + val, err := hc.URLParamInt(index) if err != nil { return def }