From c960de86f383c93e17ccc7e504d0e83cc837c4e0 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 7 Apr 2023 13:46:29 -0600 Subject: [PATCH] http writable --- http.go | 1 + http_test.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/http.go b/http.go index 6f9ee0a..b8cbb35 100644 --- a/http.go +++ b/http.go @@ -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)) }() diff --git a/http_test.go b/http_test.go index 271741c..e29bc89 100644 --- a/http_test.go +++ b/http_test.go @@ -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) + } }