dedupe via file serve

This commit is contained in:
Bel LaPointe
2022-02-08 11:50:10 -07:00
parent 3cc18ba4d5
commit af4c915b11
2 changed files with 36 additions and 13 deletions

View File

@@ -4,6 +4,8 @@ import (
"bytes"
"net/http"
"net/http/httptest"
"path"
"strings"
"testing"
)
@@ -15,14 +17,17 @@ func TestServerRoutes(t *testing.T) {
ensureAndWrite(server.diskMediaPath("id"), []byte("hi"))
ensureAndWrite(server.diskMediaPath("delid"), []byte("hi"))
ensureAndWrite(path.Join(server.root, "index.html"), []byte("mom"))
cases := map[string]struct {
path string
method string
want string
}{
"v0: /: get": {
path: "/",
method: http.MethodGet,
want: "mom",
},
"v0: search: get": {
path: "/api/v0/search",
@@ -31,10 +36,12 @@ func TestServerRoutes(t *testing.T) {
"v0: tree: get": {
path: "/api/v0/tree",
method: http.MethodGet,
want: "{}",
},
"v0: media: post": {
path: "/api/v0/media",
method: http.MethodPost,
want: `{"data":{"filePath":"/api/v0/media/`,
},
"v0: media id: del": {
path: "/api/v0/media/delid",
@@ -43,6 +50,7 @@ func TestServerRoutes(t *testing.T) {
"v0: media id: get": {
path: "/api/v0/media/id",
method: http.MethodGet,
want: "hi",
},
"v0: files: post": {
path: "/api/v0/files",
@@ -67,6 +75,9 @@ func TestServerRoutes(t *testing.T) {
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 => %s", c.method, c.path, w.Body.Bytes())
}
})