5d02404fdd
This commit introduces unit tests for the `parseCosObjectName` method in the `cosFileService`, ensuring it correctly rejects local scheme URLs and properly parses COS scheme URLs. Additionally, the `parseCosObjectName` method has been updated to return an error for unsupported schemes, improving error handling in the `GetFile` and `DeleteFile` methods. This enhancement ensures more robust handling of file paths in the application.
23 lines
695 B
Go
23 lines
695 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)
|
|
}
|