2ed5dfa6a1
iotlcm-app:小程序端 + 用户端服务。 - app/:uni-app 小程序前端(基于 unibest,MIT) - 微信 AppID → YOUR_WX_APPID,uni-app AppID → __UNI__YOURAPPID - 内网后端地址 → admin.iotlcm.example.com - 应用标题与 unibest 模板 README 重写(保留上游致谢与 MIT 声明) - server/:GoFrame 用户端服务(基于 XiuAdmin,Apache-2.0) - module xiuadmin → git.5iot.com/iotlcm-public/iotlcm-app(360 文件) - 支付回调地址 → app.iotlcm.example.com,商户名与应用名泛化 - 真实手机号 → 合法 11 位编造号(保留号段前 3 位 + 后 4 位) - 依赖号码尾部的断言同步更新 - 补 server/LICENSE(Apache-2.0) - 移除内部资产:CI 触发器 - 补根 README,LF 行尾 + .gitattributes 已知:TestSysDept_RefreshDeptAncestors 在源仓同一提交上同样失败,属既有缺陷。
88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestResolveLocalOssPathFromProjectRoot(t *testing.T) {
|
|
tempDir := t.TempDir()
|
|
relativePath := filepath.FromSlash("resource/upload/000000/user/file/test.xlsx")
|
|
realPath := filepath.Join(tempDir, "server", relativePath)
|
|
if err := os.MkdirAll(filepath.Dir(realPath), 0o755); err != nil {
|
|
t.Fatalf("mkdir test oss path: %v", err)
|
|
}
|
|
if err := os.WriteFile(realPath, []byte("xlsx"), 0o644); err != nil {
|
|
t.Fatalf("write test oss file: %v", err)
|
|
}
|
|
|
|
oldWd, err := os.Getwd()
|
|
if err != nil {
|
|
t.Fatalf("get wd: %v", err)
|
|
}
|
|
if err = os.Chdir(tempDir); err != nil {
|
|
t.Fatalf("chdir temp root: %v", err)
|
|
}
|
|
defer func() {
|
|
if err := os.Chdir(oldWd); err != nil {
|
|
t.Fatalf("restore wd: %v", err)
|
|
}
|
|
}()
|
|
|
|
got, err := NewSysOss().resolveLocalOssPath(context.Background(), relativePath)
|
|
if err != nil {
|
|
t.Fatalf("resolve local oss path: %v", err)
|
|
}
|
|
if got != realPath {
|
|
t.Fatalf("resolved path = %q, want %q", got, realPath)
|
|
}
|
|
}
|
|
|
|
func TestAppOssDownloadContentTypeXlsx(t *testing.T) {
|
|
got := appOssDownloadContentType("resource/upload/test.xlsx", "xlsx")
|
|
if got != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" {
|
|
t.Fatalf("content type = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestLocalFileURLByMappingWithProductionUploadPath(t *testing.T) {
|
|
filePath := "/data/app/iotlcmadmin-web-svc/upload/000000/user/file/20260710/sim-card-renew/result/REN-result.xlsx"
|
|
configValue := "/data/app/iotlcmadmin-web-svc/upload|http://iotlcm.example.com:8008/upload"
|
|
|
|
got, ok := localFileURLByMapping(filePath, configValue)
|
|
if !ok {
|
|
t.Fatal("expected production upload path mapping to match")
|
|
}
|
|
want := "http://iotlcm.example.com:8008/upload/000000/user/file/20260710/sim-card-renew/result/REN-result.xlsx"
|
|
if got != want {
|
|
t.Fatalf("url = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestLocalFileURLByBaseWithProductionUploadPath(t *testing.T) {
|
|
filePath := "/data/app/iotlcmadmin-web-svc/upload/000000/user/file/20260710/sim-card-renew/import/REN-import.xlsx"
|
|
got, ok := localFileURLByBase(filePath, "/data/app/iotlcmadmin-web-svc/upload", "http://iotlcm.example.com:8008/upload")
|
|
if !ok {
|
|
t.Fatal("expected upload path base mapping to match")
|
|
}
|
|
want := "http://iotlcm.example.com:8008/upload/000000/user/file/20260710/sim-card-renew/import/REN-import.xlsx"
|
|
if got != want {
|
|
t.Fatalf("url = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestLocalFileURLByMappingWithDevelopmentUploadPath(t *testing.T) {
|
|
got, ok := localFileURLByMapping(
|
|
filepath.FromSlash("resource/upload/000000/user/file/test.xlsx"),
|
|
"resource/upload|/upload",
|
|
)
|
|
if !ok {
|
|
t.Fatal("expected development upload path mapping to match")
|
|
}
|
|
if got != "/upload/000000/user/file/test.xlsx" {
|
|
t.Fatalf("url = %q", got)
|
|
}
|
|
}
|