From 4241b8372131fe177eee604e60a7dd5a84b70f40 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 20 Feb 2024 08:13:51 -0700 Subject: [PATCH] tdd ish --- cmd/server/main.go | 15 +++++++++++++++ cmd/server/main_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/cmd/server/main.go b/cmd/server/main.go index 9be3556..8e28265 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -138,5 +138,20 @@ func (h Handler) handle(session Session, w http.ResponseWriter, r *http.Request) http.FileServer(public).ServeHTTP(w, r) return nil } + switch r.URL.Path { + case "/api/v1/question": + return h.handleAPIV1Question(session, w, r) + case "/api/v1/answer": + return h.handleAPIV1Answer(session, w, r) + } + http.NotFound(w, r) + return nil +} + +func (h Handler) handleAPIV1Question(session Session, w http.ResponseWriter, r *http.Request) error { + return errors.New("not impl") +} + +func (h Handler) handleAPIV1Answer(session Session, w http.ResponseWriter, r *http.Request) error { return errors.New("not impl") } diff --git a/cmd/server/main_test.go b/cmd/server/main_test.go index 23971ad..ef306df 100644 --- a/cmd/server/main_test.go +++ b/cmd/server/main_test.go @@ -40,6 +40,44 @@ func TestRunHTTP(t *testing.T) { t.Errorf("%s", w.Body.Bytes()) } }) + + t.Run("/api/notfound", func(t *testing.T) { + r := httptest.NewRequest(http.MethodGet, "/api/notfound", nil) + r.SetBasicAuth("b", "b") + w := httptest.NewRecorder() + t.Logf("%s %s", r.Method, r.URL) + h.ServeHTTP(w, r) + t.Logf("(%d) %s", w.Code, w.Body.Bytes()) + if w.Code != http.StatusNotFound { + t.Error(w.Code) + } + }) + + t.Run("/api/v1/question", func(t *testing.T) { + r := httptest.NewRequest(http.MethodGet, "/api/v1/question", nil) + r.SetBasicAuth("b", "b") + w := httptest.NewRecorder() + t.Logf("%s %s", r.Method, r.URL) + h.ServeHTTP(w, r) + t.Logf("(%d) %s", w.Code, w.Body.Bytes()) + if w.Code != http.StatusNotFound { + t.Error(w.Code) + } + t.Errorf("not impl: %s", w.Body.Bytes()) + }) + + t.Run("/api/v1/answer", func(t *testing.T) { + r := httptest.NewRequest(http.MethodGet, "/api/v1/answer", nil) + r.SetBasicAuth("b", "b") + w := httptest.NewRecorder() + t.Logf("%s %s", r.Method, r.URL) + h.ServeHTTP(w, r) + t.Logf("(%d) %s", w.Code, w.Body.Bytes()) + if w.Code != http.StatusNotFound { + t.Error(w.Code) + } + t.Errorf("not impl: %s", w.Body.Bytes()) + }) } func TestPublic(t *testing.T) {