http writable

master
Bel LaPointe 2023-04-07 13:46:29 -06:00
parent 7a464c2f09
commit c960de86f3
2 changed files with 13 additions and 2 deletions

View File

@ -35,6 +35,7 @@ func HTTP(port int, db DB) error {
foo = withAuth(foo)
foo = withDB(foo, db)
foo = withCtx(foo, ctx)
go func() {
http.ListenAndServe(fmt.Sprintf(":%d", port), http.HandlerFunc(foo))
}()

View File

@ -7,6 +7,7 @@ import (
"path"
"strings"
"testing"
"time"
)
func TestHTTPPostQuestionAnswers(t *testing.T) {
@ -30,11 +31,20 @@ func TestHTTPPostQuestionAnswers(t *testing.T) {
if w.Code != http.StatusOK {
t.Error(w.Code)
}
t.Logf("response: %s", w.Body.Bytes())
_, got := db.LastAnswer("u", "QID")
if got == (Answer{}) {
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)
}
}