feat: file handlers (upload/list/download/delete)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"yoresee_dropbox/internal/store"
|
||||
)
|
||||
|
||||
func TestUpload(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
workspace := filepath.Join(dir, "workspace")
|
||||
os.MkdirAll(filepath.Join(workspace, "inbox"), 0755)
|
||||
|
||||
s, _ := store.Open(filepath.Join(dir, "test.db"))
|
||||
defer s.Close()
|
||||
|
||||
srv := &Server{store: s, accessToken: "token", sessions: make(map[string]int64), workspace: workspace}
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(body)
|
||||
part, _ := writer.CreateFormFile("file", "test.txt")
|
||||
part.Write([]byte("hello"))
|
||||
writer.Close()
|
||||
|
||||
req := httptest.NewRequest("POST", "/api/upload", body)
|
||||
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
req.AddCookie(&http.Cookie{Name: "ydropbox_session", Value: "valid"})
|
||||
srv.sessions["valid"] = 1
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
srv.handleUpload(w, req)
|
||||
|
||||
if w.Code != http.StatusCreated {
|
||||
t.Errorf("Status = %d, want %d", w.Code, http.StatusCreated)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user