sync: 对齐小程序 v1.0.2 生产代码并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 15:15:12 +08:00
parent a7abd476f0
commit 5fcf74deb0
423 changed files with 15001 additions and 6382 deletions
@@ -5,8 +5,58 @@ import (
"os"
"path/filepath"
"testing"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcfg"
)
func TestLocalFileURLUsesConfiguredPublicURL(t *testing.T) {
t.Setenv("IOTLCM_UPLOAD_PUBLIC_URL", "")
previous := g.Cfg().GetAdapter()
t.Cleanup(func() { g.Cfg().SetAdapter(previous) })
cases := []struct {
name string
root string
base string
file string
want string
}{
{"本地跨端预览", "resource/upload", "http://localhost:8010/upload/", "resource/upload/000000/user/file/photo.jpeg", "http://localhost:8010/upload/000000/user/file/photo.jpeg"},
{"独立部署前缀", "/data/app/upload", "https://files.example.com/app/upload", "/data/app/upload/000000/user/file/photo.jpeg", "https://files.example.com/app/upload/000000/user/file/photo.jpeg"},
{"Windows共享目录", "F:/shared/upload", "https://files.example.com/upload", "F:/shared/upload/000000/user/file/photo.jpeg", "https://files.example.com/upload/000000/user/file/photo.jpeg"},
}
for _, testCase := range cases {
t.Run(testCase.name, func(t *testing.T) {
adapter, err := gcfg.NewAdapterContent(
"system:\n upload:\n local:\n path: " + testCase.root + "\n publicUrl: " + testCase.base + "\n",
)
if err != nil {
t.Fatal(err)
}
g.Cfg().SetAdapter(adapter)
got := NewSysOss().buildLocalFileURL(context.Background(), testCase.file)
if got != testCase.want {
t.Fatalf("url = %q, want %q", got, testCase.want)
}
})
}
}
func TestLocalFileURLUsesEnvironmentOverride(t *testing.T) {
t.Setenv("IOTLCM_UPLOAD_PUBLIC_URL", "http://localhost:8010/upload")
previous := g.Cfg().GetAdapter()
t.Cleanup(func() { g.Cfg().SetAdapter(previous) })
adapter, err := gcfg.NewAdapterContent("system:\n upload:\n local:\n path: resource/upload\n publicUrl: https://files.example.com/upload\n")
if err != nil {
t.Fatal(err)
}
g.Cfg().SetAdapter(adapter)
got := NewSysOss().buildLocalFileURL(context.Background(), "resource/upload/000000/photo.jpeg")
if got != "http://localhost:8010/upload/000000/photo.jpeg" {
t.Fatalf("environment override did not take precedence: %q", got)
}
}
func TestResolveLocalOssPathFromProjectRoot(t *testing.T) {
tempDir := t.TempDir()
relativePath := filepath.FromSlash("resource/upload/000000/user/file/test.xlsx")
@@ -49,13 +99,13 @@ func TestAppOssDownloadContentTypeXlsx(t *testing.T) {
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"
configValue := "/data/app/iotlcmadmin-web-svc/upload|http://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"
want := "http://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)
}
@@ -63,11 +113,11 @@ func TestLocalFileURLByMappingWithProductionUploadPath(t *testing.T) {
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")
got, ok := localFileURLByBase(filePath, "/data/app/iotlcmadmin-web-svc/upload", "http://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"
want := "http://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)
}