Implement auth handler integration test

This commit is contained in:
2024-11-26 22:50:43 +01:00
parent e8868dde39
commit 4ddf1f570f
14 changed files with 499 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/go-chi/chi/v5"
)
// ListFiles returns a list of all files in the workspace
func (h *Handler) ListFiles() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
@@ -27,6 +28,7 @@ func (h *Handler) ListFiles() http.HandlerFunc {
}
}
// LookupFileByName returns the paths of files with the given name
func (h *Handler) LookupFileByName() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
@@ -50,6 +52,7 @@ func (h *Handler) LookupFileByName() http.HandlerFunc {
}
}
// GetFileContent returns the content of a file
func (h *Handler) GetFileContent() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
@@ -65,10 +68,15 @@ func (h *Handler) GetFileContent() http.HandlerFunc {
}
w.Header().Set("Content-Type", "text/plain")
w.Write(content)
_, err = w.Write(content)
if err != nil {
http.Error(w, "Failed to write response", http.StatusInternalServerError)
return
}
}
}
// SaveFile saves the content of a file
func (h *Handler) SaveFile() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
@@ -93,6 +101,7 @@ func (h *Handler) SaveFile() http.HandlerFunc {
}
}
// DeleteFile deletes a file
func (h *Handler) DeleteFile() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
@@ -108,10 +117,15 @@ func (h *Handler) DeleteFile() http.HandlerFunc {
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("File deleted successfully"))
_, err = w.Write([]byte("File deleted successfully"))
if err != nil {
http.Error(w, "Failed to write response", http.StatusInternalServerError)
return
}
}
}
// GetLastOpenedFile returns the last opened file in the workspace
func (h *Handler) GetLastOpenedFile() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
@@ -134,6 +148,7 @@ func (h *Handler) GetLastOpenedFile() http.HandlerFunc {
}
}
// UpdateLastOpenedFile updates the last opened file in the workspace
func (h *Handler) UpdateLastOpenedFile() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)