impl some file handles

This commit is contained in:
Bel LaPointe
2022-02-08 12:15:47 -07:00
parent af4c915b11
commit db7e7fadbf
2 changed files with 111 additions and 16 deletions

View File

@@ -17,11 +17,18 @@ func TestServerRoutes(t *testing.T) {
ensureAndWrite(server.diskMediaPath("id"), []byte("hi"))
ensureAndWrite(server.diskMediaPath("delid"), []byte("hi"))
ensureAndWrite(server.diskFilePath("getfid"), []byte("getfid body"))
ensureAndWrite(server.diskFilePath("putfid"), []byte("initial putfid body"))
ensureAndWrite(server.diskFilePath("delfid"), []byte("delfid body"))
ensureAndWrite(path.Join(server.root, "index.html"), []byte("mom"))
server.tree().Put("putfid", Branch{})
server.tree().Put("delfid", Branch{Title: "delfid title"})
server.tree().Put("getfid", Branch{Title: "getfid title"})
cases := map[string]struct {
path string
method string
body string
want string
}{
"v0: /: get": {
@@ -36,7 +43,7 @@ func TestServerRoutes(t *testing.T) {
"v0: tree: get": {
path: "/api/v0/tree",
method: http.MethodGet,
want: "{}",
want: `{"delfid":{"Title":"delfid title",`,
},
"v0: media: post": {
path: "/api/v0/media",
@@ -57,15 +64,25 @@ func TestServerRoutes(t *testing.T) {
method: http.MethodPost,
},
"v0: files id: get": {
path: "/api/v0/files/id",
path: "/api/v0/files/getfid",
method: http.MethodGet,
want: "getfid body",
},
"v0: files id: put": {
path: "/api/v0/files/putfid",
method: http.MethodPut,
body: "putfid body",
},
"v0: files id: del": {
path: "/api/v0/files/delfid",
method: http.MethodDelete,
},
}
for name, d := range cases {
c := d
t.Run(name, func(t *testing.T) {
r := httptest.NewRequest(c.method, c.path, nil)
r := httptest.NewRequest(c.method, c.path, strings.NewReader(c.body))
w := httptest.NewRecorder()
server.ServeHTTP(w, r)
if w.Code == http.StatusNotFound {
@@ -78,7 +95,7 @@ func TestServerRoutes(t *testing.T) {
if len(c.want) > 0 && !strings.Contains(string(w.Body.Bytes()), c.want) {
t.Fatal(w)
}
t.Logf("%s %s => %s", c.method, c.path, w.Body.Bytes())
t.Logf("%s %s (%+v) => %s", c.method, c.path, w.Header(), w.Body.Bytes())
}
})
}