mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
410ff14795
Remove w_uploads.storage_driver and route all read/write/delete paths through storage.Active() backed by storage_config.driver. Block direct driver switches when uploads exist; require migration task instead. Simplify migration to cursor-based file_path iteration without per-row driver updates.
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/Rain-kl/Wavelet/internal/model"
|
|
"github.com/Rain-kl/Wavelet/internal/testhelper"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestGetDistinctUploadTypes(t *testing.T) {
|
|
dbConn, _, cleanup := testhelper.SetupTestEnvironment(t)
|
|
defer cleanup()
|
|
|
|
user := model.User{ID: 2222, Username: "test_user_2"}
|
|
dbConn.Create(&user)
|
|
|
|
customUpload := model.Upload{
|
|
ID: 9001,
|
|
UserID: user.ID,
|
|
FileName: "custom.txt",
|
|
FilePath: "uploads/custom.txt",
|
|
FileSize: 10,
|
|
MimeType: "text/plain",
|
|
Extension: "txt",
|
|
Type: "custom_type_xyz",
|
|
Status: model.UploadStatusUsed,
|
|
}
|
|
dbConn.Create(&customUpload)
|
|
|
|
gin.SetMode(gin.TestMode)
|
|
r := gin.New()
|
|
r.GET("/api/v1/admin/uploads/types", GetDistinctUploadTypes)
|
|
|
|
req, _ := http.NewRequest("GET", "/api/v1/admin/uploads/types", nil)
|
|
w := httptest.NewRecorder()
|
|
r.ServeHTTP(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d", w.Code)
|
|
}
|
|
|
|
var resp struct {
|
|
ErrorMsg string `json:"error_msg"`
|
|
Data []string `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("failed to parse JSON: %v", err)
|
|
}
|
|
|
|
if resp.ErrorMsg != "" {
|
|
t.Fatalf("unexpected error: %s", resp.ErrorMsg)
|
|
}
|
|
|
|
if len(resp.Data) != 1 || resp.Data[0] != "custom_type_xyz" {
|
|
t.Errorf("expected only custom_type_xyz in types list, got: %v", resp.Data)
|
|
}
|
|
} |