mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
thirdUpload dispatched on the source parameter and then built the same
zero-value ALiYunOSS in both branches, so source=3 could not have
reached qiniu even with credentials.
Neither branch had credentials to use. OXS.Setup is the initialisation
path and nothing in the repository called it, and no configuration field
existed to fill. The store is now taken from extend.fileStore, and a
provider that was not configured says so rather than producing the
provider's own complaint about an empty bucket name.
The two handlers passed errors.New("") to e.Error, discarding what
actually went wrong; they now pass the error.
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package apis
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"go-admin/config"
|
|
)
|
|
|
|
// Both branches used to construct a zero-value ALiYunOSS and call UpLoad on it,
|
|
// which panicked; the qiniu branch built the aliyun client, so source=3 could
|
|
// not have reached qiniu even with credentials. Unconfigured now reports which
|
|
// store is missing.
|
|
func TestThirdUploadReportsAnUnconfiguredStore(t *testing.T) {
|
|
previous := config.ExtConfig.FileStore
|
|
config.ExtConfig.FileStore = config.FileStore{}
|
|
t.Cleanup(func() { config.ExtConfig.FileStore = previous })
|
|
|
|
for source, want := range map[string]string{"2": "AliYunOSS", "3": "QiNiuKodo"} {
|
|
err := thirdUpload(source, "x.png", "/tmp/x.png")
|
|
if err == nil {
|
|
t.Errorf("source=%s: no error from an unconfigured store", source)
|
|
continue
|
|
}
|
|
if !strings.Contains(err.Error(), want) {
|
|
t.Errorf("source=%s: error names %q, want it to mention %s", source, err, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// source 1 and anything unrecognised keep the local copy and do nothing else.
|
|
func TestThirdUploadIgnoresLocalAndUnknownSources(t *testing.T) {
|
|
for _, source := range []string{"", "1", "9"} {
|
|
if err := thirdUpload(source, "x.png", "/tmp/x.png"); err != nil {
|
|
t.Errorf("source=%q returned %v, want nil", source, err)
|
|
}
|
|
}
|
|
}
|