fix: upload image issues
This commit is contained in:
50
backend/tests/storage_test.go
Normal file
50
backend/tests/storage_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
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.
|
||||
}
|
||||
Reference in New Issue
Block a user