mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-15 17:12:14 +03:00
74 lines
2.3 KiB
YAML
74 lines
2.3 KiB
YAML
name: File Generation and Reading Test
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- v2/test-ci-windows
|
|
pull_request:
|
|
branches:
|
|
- v2/test-ci-windows
|
|
|
|
|
|
jobs:
|
|
file-test:
|
|
runs-on: windows-latest # 使用 Windows 运行器
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Generate test files (Step 1)
|
|
shell: powershell
|
|
run: |
|
|
# 创建工作目录
|
|
$testDir = "${{ github.workspace }}\test-files"
|
|
New-Item -ItemType Directory -Path $testDir -Force
|
|
|
|
# 创建几个测试文件
|
|
"This is a test content for file1.txt" | Out-File -FilePath "$testDir\file1.txt"
|
|
"fuzzy.def test content" | Out-File -FilePath "$testDir\fuzzy.def"
|
|
|
|
# 创建一个包含文件列表的 JSON 文件
|
|
$files = Get-ChildItem -Path $testDir
|
|
$fileInfo = @()
|
|
foreach ($file in $files) {
|
|
$fileInfo += @{
|
|
Name = $file.Name
|
|
Path = $file.FullName
|
|
Size = $file.Length
|
|
LastWriteTime = $file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
|
|
}
|
|
}
|
|
$fileInfo | ConvertTo-Json | Out-File -FilePath "$testDir\files.json"
|
|
|
|
# 输出生成的文件信息
|
|
Write-Host "Generated files:"
|
|
Get-ChildItem -Path $testDir | Format-Table Name, Length
|
|
|
|
- name: Read test files (Step 2)
|
|
shell: powershell
|
|
run: |
|
|
$testDir = "${{ github.workspace }}\test-files"
|
|
|
|
# 检查目录是否存在
|
|
if (-not (Test-Path -Path $testDir)) {
|
|
Write-Error "Test directory does not exist!"
|
|
exit 1
|
|
}
|
|
|
|
# 读取文件列表
|
|
$filesJson = Get-Content -Path "$testDir\files.json" -Raw | ConvertFrom-Json
|
|
Write-Host "Files found:"
|
|
$filesJson | Format-Table Name, Size
|
|
|
|
# 读取特定文件内容
|
|
Write-Host "Content of fuzzy.def:"
|
|
Get-Content -Path "$testDir\fuzzy.def"
|
|
|
|
# 验证文件存在
|
|
if (Test-Path -Path "$testDir\fuzzy.def") {
|
|
Write-Host "SUCCESS: fuzzy.def file exists and is accessible!"
|
|
} else {
|
|
Write-Error "ERROR: fuzzy.def file not found!"
|
|
exit 1
|
|
} |