Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Fix ignoring query strings
Browse files Browse the repository at this point in the history
  • Loading branch information
scoiatael committed Mar 9, 2017
1 parent a3310f7 commit 07a7cc4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions actions/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
21 changes: 18 additions & 3 deletions actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"net/http"
"time"

. "github.com/scoiatael/archai"
"github.com/scoiatael/archai/actions"
Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -87,16 +89,29 @@ 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)
Expect(err).NotTo(HaveOccurred())
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())
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions http/iris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 07a7cc4

Please sign in to comment.