test media del

master
Bel LaPointe 2022-02-08 11:27:28 -07:00
parent 57f24b2f33
commit 3cc18ba4d5
2 changed files with 13 additions and 0 deletions

View File

@ -102,11 +102,19 @@ func (server *Server) apiV0MediaIDHandler(w http.ResponseWriter, r *http.Request
switch r.Method { switch r.Method {
case http.MethodGet: case http.MethodGet:
return server.apiV0MediaIDGetHandler(w, r) return server.apiV0MediaIDGetHandler(w, r)
case http.MethodDelete:
return server.apiV0MediaIDDelHandler(w, r)
} }
http.NotFound(w, r) http.NotFound(w, r)
return nil return nil
} }
func (server *Server) apiV0MediaIDDelHandler(w http.ResponseWriter, r *http.Request) error {
id := path.Base(r.URL.Path)
os.Remove(server.diskMediaPath(id))
return nil
}
func (server *Server) apiV0MediaIDGetHandler(w http.ResponseWriter, r *http.Request) error { func (server *Server) apiV0MediaIDGetHandler(w http.ResponseWriter, r *http.Request) error {
id := path.Base(r.URL.Path) id := path.Base(r.URL.Path)
f, err := os.Open(server.diskMediaPath(id)) f, err := os.Open(server.diskMediaPath(id))

View File

@ -14,6 +14,7 @@ func TestServerRoutes(t *testing.T) {
} }
ensureAndWrite(server.diskMediaPath("id"), []byte("hi")) ensureAndWrite(server.diskMediaPath("id"), []byte("hi"))
ensureAndWrite(server.diskMediaPath("delid"), []byte("hi"))
cases := map[string]struct { cases := map[string]struct {
path string path string
@ -35,6 +36,10 @@ func TestServerRoutes(t *testing.T) {
path: "/api/v0/media", path: "/api/v0/media",
method: http.MethodPost, method: http.MethodPost,
}, },
"v0: media id: del": {
path: "/api/v0/media/delid",
method: http.MethodDelete,
},
"v0: media id: get": { "v0: media id: get": {
path: "/api/v0/media/id", path: "/api/v0/media/id",
method: http.MethodGet, method: http.MethodGet,