|
| 1 | +function Set-SnmpTestEnvironment { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Configure SNMP test environment: set MIBDIRS, patch snmpd.conf, and start snmpd. |
| 5 | + .PARAMETER TestsDirectoryPath |
| 6 | + Absolute path to the extracted PHP tests directory (use the $testsDirectoryPath from Add-TestRequirements). |
| 7 | + #> |
| 8 | + [CmdletBinding()] |
| 9 | + param ( |
| 10 | + [Parameter(Mandatory = $true)] |
| 11 | + [ValidateNotNullOrEmpty()] |
| 12 | + [string] $TestsDirectoryPath |
| 13 | + ) |
| 14 | + process { |
| 15 | + if (-not $env:DEPS_DIR) { |
| 16 | + throw 'DEPS_DIR is not set. Ensure dependencies are downloaded before SNMP setup.' |
| 17 | + } |
| 18 | + |
| 19 | + $env:MIBDIRS = Join-Path $env:DEPS_DIR 'share\mibs' |
| 20 | + |
| 21 | + $confPath = Join-Path $TestsDirectoryPath 'ext\snmp\tests\snmpd.conf' |
| 22 | + if (-not (Test-Path -LiteralPath $confPath)) { |
| 23 | + throw "snmpd.conf not found at $confPath" |
| 24 | + } |
| 25 | + |
| 26 | + $forwardTestsRoot = ($TestsDirectoryPath -replace '\\','/') |
| 27 | + $bigTestJs = "$forwardTestsRoot/ext/snmp/tests/bigtest.js" |
| 28 | + |
| 29 | + $content = Get-Content -LiteralPath $confPath -Raw -Encoding UTF8 |
| 30 | + $newLine = "exec HexTest cscript.exe /nologo $bigTestJs" |
| 31 | + $updated = [System.Text.RegularExpressions.Regex]::Replace( |
| 32 | + $content, |
| 33 | + '^exec\s+HexTest\s+.*$', |
| 34 | + [System.Text.RegularExpressions.Regex]::Escape($newLine).Replace('\/','/'), |
| 35 | + [System.Text.RegularExpressions.RegexOptions]::Multiline |
| 36 | + ) |
| 37 | + if ($updated -ne $content) { |
| 38 | + Set-Content -LiteralPath $confPath -Value $updated -Encoding UTF8 |
| 39 | + } |
| 40 | + |
| 41 | + $snmpd = Join-Path $env:DEPS_DIR 'bin\snmpd.exe' |
| 42 | + if (-not (Test-Path -LiteralPath $snmpd)) { |
| 43 | + throw "snmpd.exe not found at $snmpd" |
| 44 | + } |
| 45 | + Start-Process -FilePath $snmpd -ArgumentList @('-C','-c', $confPath, '-Ln') -WindowStyle Hidden | Out-Null |
| 46 | + } |
| 47 | +} |
0 commit comments