e0823eff31
This commit introduces a new test suite for the IM file service, including a stub implementation for testing purposes. It adds tests for resolving file services based on storage providers and ensures proper fallback mechanisms for MinIO URLs. Additionally, the `rewriteStorageURLs` and `cleanIMContent` functions have been refactored to utilize a resolver for improved caching and efficiency. These changes enhance the robustness of file service handling and improve test coverage for various storage scenarios.
30 lines
983 B
Go
30 lines
983 B
Go
package file
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestParseCosObjectName_RejectsLocalScheme(t *testing.T) {
|
|
svc := &cosFileService{bucketURL: "https://b.cos.ap-shanghai.myqcloud.com/"}
|
|
_, err := svc.parseCosObjectName("local://10000/exports/img.png")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "local")
|
|
}
|
|
|
|
func TestParseCosObjectName_CosScheme(t *testing.T) {
|
|
svc := &cosFileService{bucketURL: "https://b.cos.ap-shanghai.myqcloud.com/"}
|
|
key, err := svc.parseCosObjectName("cos://bucket/ap-shanghai/weknora/10000/exports/a.png")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "weknora/10000/exports/a.png", key)
|
|
}
|
|
|
|
func TestParseCosObjectName_RejectsMinioScheme(t *testing.T) {
|
|
svc := &cosFileService{bucketURL: "https://b.cos.ap-shanghai.myqcloud.com/"}
|
|
_, err := svc.parseCosObjectName("minio://wizard-test/10000/exports/img.png")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "minio")
|
|
}
|