Files
quyun-v2/backend/tests/storage_test.go
Rogee 221b068a84 feat: add file deduplication and hash checking for uploads
- Implemented SHA-256 hashing for uploaded files to enable deduplication.
- Added CheckHash method to verify if a file with the same hash already exists.
- Updated Upload method to reuse existing media assets if a duplicate is found.
- Introduced a new hash column in the media_assets table to store file hashes.
- Enhanced the upload process to include progress tracking and hash calculation.
- Modified frontend to check for existing files before uploading and to show upload progress.
- Added vuedraggable for drag-and-drop functionality in the content editing view.
2025-12-31 19:16:02 +08:00

51 lines
1.6 KiB
Go

package tests
import (
"testing"
"time"
"quyun/v2/providers/storage"
. "github.com/smartystreets/goconvey/convey"
)
func TestStorageProvider(t *testing.T) {
Convey("Storage Provider Test", t, func() {
// Mock Config to match what we expect in config.toml
// We use a map to simulate how unmarshal might see it, or just use the Config struct directly if we can manual init.
// But provider uses UnmarshalConfig.
// To test properly, we should try to boot the provider or check the logic.
// Let's manually init the Storage struct with the config we expect to be loaded.
cfg := &storage.Config{
Type: "local",
LocalPath: "./storage",
Secret: "your-storage-secret",
BaseURL: "http://localhost:8080/v1/storage",
}
s := &storage.Storage{Config: cfg}
Convey("SignURL should return absolute URL with BaseURL", func() {
key := "test.png"
url, err := s.SignURL("GET", key, 1*time.Hour)
So(err, ShouldBeNil)
// Log for debugging
t.Logf("Generated URL: %s", url)
So(url, ShouldStartWith, "http://localhost:8080/v1/storage/test.png")
So(url, ShouldContainSubstring, "sign=")
})
})
}
// Helper to test if config loading actually works (integration test)
func TestStorageConfigLoading(t *testing.T) {
// This requires setting up the atom container/config loader which is complex in unit test without full boot.
// But we can check if `Provide` works with a mock config source if possible.
// For now, we trust the logic that if Config is loaded, SignURL works.
// The previous issue was likely Config NOT loaded or loaded empty.
}