您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

67 行
2.5KB

  1. [CmdletBinding()]
  2. param(
  3. [Parameter(Mandatory = $true)]
  4. [string]$BaseUrl
  5. )
  6. $script:failures = 0
  7. function Report {
  8. param($ok, $label, $detail)
  9. if ($ok) {
  10. Write-Output "PASS: $label"
  11. } else {
  12. Write-Output "FAIL: $label ($detail)"
  13. $script:failures++
  14. }
  15. }
  16. try {
  17. $resp = Invoke-WebRequest -Uri "$BaseUrl/hello" -UseBasicParsing
  18. Report ($resp.StatusCode -eq 200) "GET /hello status 200" "got $($resp.StatusCode)"
  19. Report ($resp.Headers['Content-Type'] -eq 'text/html; charset=utf-8') "GET /hello content-type" "got $($resp.Headers['Content-Type'])"
  20. Report ($resp.Content -eq 'Hello from WSC-MVC!') "GET /hello body" "got '$($resp.Content)'"
  21. } catch {
  22. Report $false "GET /hello request" $_.Exception.Message
  23. }
  24. # GET /self-test is the frontend-agnostic JSON harness (Controllers/SelfTestController.wsc) -
  25. # callable from any CLI via plain HTTP, not just PowerShell/cscript on the VM. This exercises
  26. # the same component-level checks as tests/Test-Components.vbs, in-process, over HTTP.
  27. try {
  28. $selfTestResp = Invoke-WebRequest -Uri "$BaseUrl/self-test" -UseBasicParsing
  29. Report ($selfTestResp.StatusCode -eq 200) "GET /self-test status 200" "got $($selfTestResp.StatusCode)"
  30. Report ($selfTestResp.Headers['Content-Type'] -eq 'application/json; charset=utf-8') "GET /self-test content-type" "got $($selfTestResp.Headers['Content-Type'])"
  31. $selfTestJson = $selfTestResp.Content | ConvertFrom-Json
  32. foreach ($check in $selfTestJson.checks) {
  33. Report ([bool]$check.pass) "self-test: $($check.name)" $check.detail
  34. }
  35. Report ([bool]$selfTestJson.ok) "GET /self-test overall ok" "detail in individual checks above"
  36. } catch {
  37. Report $false "GET /self-test request" $_.Exception.Message
  38. }
  39. try {
  40. $wscResp = Invoke-WebRequest -Uri "$BaseUrl/Framework/Application.wsc" -UseBasicParsing
  41. Report $false "GET /Framework/Application.wsc denied" "got $($wscResp.StatusCode)"
  42. } catch [System.Net.WebException] {
  43. $webResp = $_.Exception.Response
  44. if ($webResp) {
  45. $code = [int]$webResp.StatusCode
  46. Report ($code -eq 404) "GET /Framework/Application.wsc denied" "got $code"
  47. } else {
  48. Report $false "GET /Framework/Application.wsc denied" $_.Exception.Message
  49. }
  50. } catch {
  51. Report $false "GET /Framework/Application.wsc denied" $_.Exception.Message
  52. }
  53. Write-Output "---"
  54. if ($script:failures -eq 0) {
  55. Write-Output "RESULT: ALL PASS"
  56. exit 0
  57. } else {
  58. Write-Output "RESULT: $($script:failures) FAILURE(S)"
  59. exit 1
  60. }

Powered by TurnKey Linux.