This commit is contained in:
2026-01-07 16:50:42 +08:00
parent 9e42257e4e
commit ec72e47695
16 changed files with 981 additions and 27 deletions

View File

@@ -254,7 +254,7 @@ func TestGenerateAuthorizationDocument(t *testing.T) {
assert.False(t, authDoc.ExpireTime.Valid) // 永久保留,不设置过期时间
// 验证文件路径格式兼容Windows和Unix路径分隔符
assert.True(t, strings.Contains(authDoc.FilePath, "data/authorization_docs") ||
assert.True(t, strings.Contains(authDoc.FilePath, "data/authorization_docs") ||
strings.Contains(authDoc.FilePath, "data\\authorization_docs"))
assert.Contains(t, authDoc.FileName, "auth_")
assert.Contains(t, authDoc.FileName, ".pdf")
@@ -372,7 +372,7 @@ func TestGeneratePDFContent(t *testing.T) {
t.Logf("📁 文件路径: %s", filePath)
t.Logf("🔗 相对路径: %s", relativePath)
t.Logf("📊 文件大小: %d 字节", len(pdfBytes))
// 获取绝对路径
absPath, _ := filepath.Abs(filePath)
t.Logf("📍 绝对路径: %s", absPath)
@@ -430,16 +430,16 @@ func TestSavePDFToLocal(t *testing.T) {
t.Logf("📁 文件路径: %s", filePath)
t.Logf("🔗 相对路径: %s", relativePath)
t.Logf("📊 文件大小: %d 字节", len(pdfBytes))
// 获取绝对路径
absPath, _ := filepath.Abs(filePath)
t.Logf("📍 绝对路径: %s", absPath)
// 验证文件内容
fileInfo, err := os.Stat(filePath)
assert.NoError(t, err)
assert.Greater(t, fileInfo.Size(), int64(1000)) // 文件应该大于1KB
t.Logf("🎉 文件保存验证通过!")
} else {
t.Errorf("❌ PDF文件保存失败: %v", err)
@@ -648,18 +648,18 @@ func TestGeneratePDFFile(t *testing.T) {
t.Logf("📁 文件路径: %s", authDoc.FilePath)
t.Logf("🔗 相对路径: %s", authDoc.FileUrl)
t.Logf("📊 文件大小: %d 字节", authDoc.FileSize)
// 验证文件内容
fileInfo, err := os.Stat(authDoc.FilePath)
assert.NoError(t, err)
assert.Greater(t, fileInfo.Size(), int64(1000)) // 文件应该大于1KB
// 验证文件名格式
assert.Regexp(t, `^auth_999_888_\d{8}_\d{6}\.pdf$`, authDoc.FileName)
// 验证路径格式
assert.Regexp(t, `^\d{4}/\d{2}/auth_999_888_\d{8}_\d{6}\.pdf$`, authDoc.FileUrl)
t.Logf("🎉 所有验证通过!")
} else {
t.Errorf("❌ PDF文件未创建: %s", authDoc.FilePath)