Compare commits

..
3 Commits
7 changed files with 59 additions and 17 deletions
+2
View File
@@ -29,6 +29,8 @@ testrun2/
freshtest/
cfgtest/
cfgtest-run/
config-run/
portability-run/
portable-run/
# 截图辅助
+4
View File
@@ -172,6 +172,10 @@
>
> **为什么内嵌时区库**:Windows 没有 `/usr/share/zoneinfo`,为了 `timezone = Asia/Shanghai` 在任何机器上都可用,引入了 `time/tzdata`(约 0.5 MB)。
> 改了依赖之后,请在 Windows 上额外跑一次 `GOOS=linux go build ./...` 再提交 `go.sum`:
> 有些依赖(例如 `modernc.org/libc` 的 Linux 专用文件)只在 Linux 构建路径下被编译,
> 只在本机 Windows 构建会漏掉它们的 `go.sum` 条目,导致 CI 报 `missing go.sum entry`。
测试:
```powershell
+2
View File
@@ -1,5 +1,7 @@
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
+3 -2
View File
@@ -64,6 +64,7 @@ func TestLoadCreatesDefaultFile(t *testing.T) {
func TestLoadParsesValues(t *testing.T) {
dir := t.TempDir()
absLogDir := t.TempDir() // 各平台都是绝对路径,避免把 Windows 盘符写进用例
body := "\ufeff# 注释\n" +
"listen_ip = 127.0.0.1\r\n" +
"\r\n" +
@@ -75,7 +76,7 @@ func TestLoadParsesValues(t *testing.T) {
"open_browser = 0\r\n" +
"screen_public = false\r\n" +
"log_enabled = on\r\n" +
"log_dir = D:\\logs\r\n"
"log_dir = " + absLogDir + "\r\n"
path := writeFile(t, dir, FileName, body)
cfg, err := Load(path, dir)
@@ -97,7 +98,7 @@ func TestLoadParsesValues(t *testing.T) {
if cfg.Timezone != "Asia/Shanghai" || cfg.OpenBrowser || cfg.ScreenPublic || !cfg.LogEnabled {
t.Fatalf("其余配置不对: %+v", cfg)
}
if cfg.LogDir != "D:\\logs" {
if cfg.LogDir != absLogDir {
t.Fatalf("绝对路径被改写: %s", cfg.LogDir)
}
if cfg.Addr() != "127.0.0.1:19000" {
+28 -7
View File
@@ -2,10 +2,11 @@
# 用法: powershell -NoProfile -ExecutionPolicy Bypass -File scripts\acceptance.ps1 -Base http://127.0.0.1:18090 -Db <测试库路径>
param(
[string]$Base = 'http://127.0.0.1:18090',
[string]$Db = 'F:\hupeE的代肝平台\testrun\daili.db',
[string]$Python = 'E:\Miniconda3\python.exe',
[string]$Tools = 'F:\hupeE的代肝平台\scripts\dbtool.py',
[string]$LogFile = 'F:\hupeE的代肝平台\testrun\acceptance-result.txt'
[string]$Root = '',
[string]$Db = '',
[string]$Python = '',
[string]$Tools = '',
[string]$LogFile = ''
)
try { Add-Type -AssemblyName System.Net.Http -ErrorAction Stop } catch { }
@@ -13,6 +14,26 @@ try { Add-Type -AssemblyName System.Net.Http -ErrorAction Stop } catch { }
$ErrorActionPreference = 'Continue'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$env:PYTHONIOENCODING = 'utf-8'
# ---- 路径与外部程序:全部基于脚本所在目录,换机器/换目录都不用改 ----
function Find-Python {
foreach ($c in @($env:PYTHON, 'python', 'py')) {
if (-not $c) { continue }
$cmd = Get-Command $c -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
}
foreach ($p in @('E:\Miniconda3\python.exe', 'C:\Python312\python.exe', 'C:\Python311\python.exe')) {
if (Test-Path $p) { return $p }
}
throw '找不到 Python 解释器,请用 -Python 指定路径'
}
if (-not $Root) { $Root = Split-Path -Parent $PSScriptRoot }
if (-not $Db) { $Db = Join-Path $Root 'testrun\daili.db' }
if (-not $Tools) { $Tools = Join-Path $Root 'scripts\dbtool.py' }
if (-not $LogFile) { $LogFile = Join-Path $Root 'testrun\acceptance-result.txt' }
if (-not $Python) { $Python = Find-Python }
$BackupDir = Join-Path $Root 'testrun\backup'
$LogDir = Join-Path $Root 'testrun\logs'
$VerifyScript = Join-Path $Root 'scripts\verify-backup.py'
$script:results = @()
$script:fail = 0
$T = (Get-Date).Date
@@ -444,7 +465,7 @@ Check 'R-06' '日志 CSV 含操作人/动作' ((Has $csv3 '操作人') -and (Has
$r = Send $admin 'POST' '/settings/backup'
Check 'R-07' '手动备份生成文件' ((Has $r.Content '已备份')) "flash=$(Flash $r.Content)"
$verify = (& $Python 'F:\hupeE的代肝平台\scripts\verify-backup.py' 'F:\hupeE的代肝平台\testrun\backup') -join ' '
$verify = (& $Python $VerifyScript $BackupDir) -join ' '
Check 'R-07b' '备份文件可被标准 SQLite 打开且有数据' (($verify -match 'OK') -and ($verify -match 'customers\s+(\d+)')) $verify
Send $admin 'POST' '/settings' @{ warn_days = '3'; screen_refresh = '30' } | Out-Null
@@ -453,7 +474,7 @@ for ($i = 0; $i -lt 3; $i++) {
Start-Sleep -Milliseconds 1200
Send $admin 'POST' '/settings/backup' | Out-Null
}
$bk = @(Get-ChildItem 'F:\hupeE的代肝平台\testrun\backup' -Filter 'daili-*.db')
$bk = @(Get-ChildItem $BackupDir -Filter 'daili-*.db')
$pruneOk = ($keepShown -ge 1) -and ($bk.Count -le $keepShown) -and (($keepShown -gt 3) -or ($bk.Count -eq $keepShown))
Check 'R-08' "备份保留份数生效(配置 $keepShown 份)" $pruneOk "count=$($bk.Count) keep=$keepShown"
@@ -537,7 +558,7 @@ Check 'CF-02' '设置页展示备份目录与保留份数' ((Has $settingsHtml '
$anon2 = New-Sess
$r = Send $anon2 'GET' '/screen'
Check 'CF-03' '大屏免登录(screen_public = true)' ($r.Status -eq 200 -and $r.Path -eq '/screen') "status=$($r.Status) path=$($r.Path)"
$logs = @(Get-ChildItem 'F:\hupeE的代肝平台\testrun\logs' -Filter '*.log' -ErrorAction SilentlyContinue)
$logs = @(Get-ChildItem $LogDir -Filter '*.log' -ErrorAction SilentlyContinue)
$logText = ''
if ($logs.Count -ge 1) { $logText = Get-Content $logs[0].FullName -Raw -Encoding UTF8 }
Check 'CF-04' '运行日志落盘' ($logs.Count -ge 1 -and $logText.Length -gt 20) "files=$($logs.Count) bytes=$($logText.Length)"
+10 -4
View File
@@ -1,11 +1,17 @@
# 配置文件专项测试:验证 daili.ini 的生成、解析、覆盖与各项生效
# 用法: powershell -NoProfile -ExecutionPolicy Bypass -File scripts\config-test.ps1
param(
[string]$Exe = 'F:\hupeE的代肝平台\daili.exe',
[string]$Work = 'F:\hupeE的代肝平台\cfgtest-run',
[string]$Exe = '',
[string]$Work = '',
[string]$LanIp = ''
)
$Root = Split-Path -Parent $PSScriptRoot
if (-not $Exe) { $Exe = Join-Path $Root 'daili.exe' }
if (-not $Work) { $Work = Join-Path $Root 'config-run' }
$Evidence = Join-Path $Root 'test-evidence'
if (-not (Test-Path $Exe)) { throw "找不到被测程序:$Exe(先构建或已用 -Exe 指定)" }
$ErrorActionPreference = 'Continue'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Add-Type -AssemblyName System.Net.Http
@@ -226,8 +232,8 @@ Stop-App $h
$pass = @($script:results | Where-Object { $_ -like 'PASS|*' }).Count
$fail = @($script:results | Where-Object { $_ -like 'FAIL|*' }).Count
Write-Host "`n=== 汇总:通过 $pass 项,失败 $fail 项 ===" -ForegroundColor ($(if ($fail -eq 0) { 'Green' } else { 'Red' }))
New-Item -ItemType Directory -Force -Path 'F:\hupeE的代肝平台\test-evidence' | Out-Null
$script:results | Set-Content 'F:\hupeE的代肝平台\test-evidence\config-result.txt' -Encoding UTF8
New-Item -ItemType Directory -Force -Path $Evidence | Out-Null
$script:results | Set-Content (Join-Path $Evidence 'config-result.txt') -Encoding UTF8
Remove-Item -Recurse -Force $Work -ErrorAction SilentlyContinue
if ($fail -gt 0) { exit 1 }
exit 0
+10 -4
View File
@@ -1,12 +1,18 @@
# 数据可移植性测试:单文件、只拷 daili.db 无损迁移、删库即重置
# 用法: powershell -NoProfile -ExecutionPolicy Bypass -File scripts\portability-test.ps1
param(
[string]$Exe = 'F:\hupeE的代肝平台\daili.exe',
[string]$Work = 'F:\hupeE的代肝平台\portable-run',
[string]$Exe = '',
[string]$Work = '',
[int]$PortA = 17781,
[int]$PortB = 17782
)
$Root = Split-Path -Parent $PSScriptRoot
if (-not $Exe) { $Exe = Join-Path $Root 'daili.exe' }
if (-not $Work) { $Work = Join-Path $Root 'portability-run' }
$Evidence = Join-Path $Root 'test-evidence'
if (-not (Test-Path $Exe)) { throw "找不到被测程序:$Exe(先构建或已用 -Exe 指定)" }
$ErrorActionPreference = 'Continue'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Add-Type -AssemblyName System.Net.Http
@@ -153,8 +159,8 @@ Stop-App $hA2
$pass = @($script:results | Where-Object { $_ -like 'PASS|*' }).Count
$fail = @($script:results | Where-Object { $_ -like 'FAIL|*' }).Count
Write-Host "`n=== 汇总:通过 $pass 项,失败 $fail 项 ===" -ForegroundColor ($(if ($fail -eq 0) { 'Green' } else { 'Red' }))
New-Item -ItemType Directory -Force -Path 'F:\hupeE的代肝平台\test-evidence' | Out-Null
$script:results | Set-Content 'F:\hupeE的代肝平台\test-evidence\portability-result.txt' -Encoding UTF8
New-Item -ItemType Directory -Force -Path $Evidence | Out-Null
$script:results | Set-Content (Join-Path $Evidence 'portability-result.txt') -Encoding UTF8
Remove-Item -Recurse -Force $Work -ErrorAction SilentlyContinue
if ($fail -gt 0) { exit 1 }
exit 0