impl http api server for serving index.html, api calls

This commit is contained in:
Bel LaPointe
2022-02-08 12:40:34 -07:00
parent db7e7fadbf
commit 09b3e4a002
2 changed files with 51 additions and 11 deletions

View File

@@ -1,7 +1,6 @@
package main
import (
"bytes"
"net/http"
"net/http/httptest"
"path"
@@ -37,8 +36,9 @@ func TestServerRoutes(t *testing.T) {
want: "mom",
},
"v0: search: get": {
path: "/api/v0/search",
path: "/api/v0/search?q=getf%20bod",
method: http.MethodGet,
want: `["getfid"]`,
},
"v0: tree: get": {
path: "/api/v0/tree",
@@ -88,15 +88,13 @@ func TestServerRoutes(t *testing.T) {
if w.Code == http.StatusNotFound {
t.Fatal(w)
}
if !bytes.HasPrefix(w.Body.Bytes(), []byte("not impl")) {
if w.Code != http.StatusOK {
t.Fatal(w)
}
if len(c.want) > 0 && !strings.Contains(string(w.Body.Bytes()), c.want) {
t.Fatal(w)
}
t.Logf("%s %s (%+v) => %s", c.method, c.path, w.Header(), w.Body.Bytes())
if w.Code != http.StatusOK {
t.Fatal(w)
}
if len(c.want) > 0 && !strings.Contains(string(w.Body.Bytes()), c.want) {
t.Fatal(w)
}
t.Logf("%s %s (%+v) => %s", c.method, c.path, w.Header(), w.Body.Bytes())
})
}
}