http writable
parent
7a464c2f09
commit
c960de86f3
1
http.go
1
http.go
|
|
@ -35,6 +35,7 @@ func HTTP(port int, db DB) error {
|
||||||
foo = withAuth(foo)
|
foo = withAuth(foo)
|
||||||
foo = withDB(foo, db)
|
foo = withDB(foo, db)
|
||||||
foo = withCtx(foo, ctx)
|
foo = withCtx(foo, ctx)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
http.ListenAndServe(fmt.Sprintf(":%d", port), http.HandlerFunc(foo))
|
http.ListenAndServe(fmt.Sprintf(":%d", port), http.HandlerFunc(foo))
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
14
http_test.go
14
http_test.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPPostQuestionAnswers(t *testing.T) {
|
func TestHTTPPostQuestionAnswers(t *testing.T) {
|
||||||
|
|
@ -30,11 +31,20 @@ func TestHTTPPostQuestionAnswers(t *testing.T) {
|
||||||
if w.Code != http.StatusOK {
|
if w.Code != http.StatusOK {
|
||||||
t.Error(w.Code)
|
t.Error(w.Code)
|
||||||
}
|
}
|
||||||
t.Logf("response: %s", w.Body.Bytes())
|
|
||||||
|
|
||||||
_, got := db.LastAnswer("u", "QID")
|
_, got := db.LastAnswer("u", "QID")
|
||||||
if got == (Answer{}) {
|
if got == (Answer{}) {
|
||||||
t.Error("no answer pushed:", got)
|
t.Error("no answer pushed:", got)
|
||||||
}
|
}
|
||||||
t.Logf("answer pushed: %+v", got)
|
if got.Q != "QID" {
|
||||||
|
t.Error(got.Q)
|
||||||
|
} else if got.A != "a" {
|
||||||
|
t.Error(got.A)
|
||||||
|
} else if time.Since(time.Unix(0, got.TS)) > time.Minute {
|
||||||
|
t.Error(got.TS)
|
||||||
|
} else if got.Author != "u" {
|
||||||
|
t.Error(got.Author)
|
||||||
|
} else if got.Pass != false {
|
||||||
|
t.Error(got.Pass)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue