put is upsert for files

This commit is contained in:
Bel LaPointe
2022-02-08 15:26:33 -07:00
parent d0cea24d88
commit 1e01088b92
2 changed files with 32 additions and 6 deletions

View File

@@ -113,6 +113,29 @@ func TestServerPutTreeGetFile(t *testing.T) {
}
server.tree().Put("my pid", Branch{})
var id string
t.Run("put to create an id", func(t *testing.T) {
r := httptest.NewRequest(http.MethodPut, "/my-put-id", strings.NewReader("body"))
r.Header.Set("Title", "my put title")
r.Header.Set("PID", "my pid")
w := httptest.NewRecorder()
if err := server.apiV0FilesIDHandler(w, r); err != nil {
t.Fatal(err)
}
if w.Code != http.StatusOK {
t.Fatal(w)
}
var resp struct {
Data struct {
FilePath string `json:"filePath"`
} `json:"data"`
}
if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
t.Fatal(err)
}
if path.Base(resp.Data.FilePath) != "my-put-id" {
t.Fatal(resp.Data.FilePath)
}
})
t.Run("post", func(t *testing.T) {
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader("body"))
r.Header.Set("Title", "my title")