Merge pull request #25 from dmilov/topic/dmilov/fix-integration-tests-run
This commit is contained in:
commit
427100c4c2
|
@ -9,7 +9,7 @@
|
||||||
RootModule = 'CloudEvents.Sdk.psm1'
|
RootModule = 'CloudEvents.Sdk.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '0.2.0'
|
ModuleVersion = '0.2.1'
|
||||||
|
|
||||||
# Supported PSEditions
|
# Supported PSEditions
|
||||||
CompatiblePSEditions = @('Core')
|
CompatiblePSEditions = @('Core')
|
||||||
|
|
|
@ -556,7 +556,7 @@ PROCESS {
|
||||||
$headers.Add(($HttpHeaderPrefix + $attribute.Key), $attribute.Value.ToString())
|
$headers.Add(($HttpHeaderPrefix + $attribute.Key), $attribute.Value.ToString())
|
||||||
}
|
}
|
||||||
elseif ($attribute.Value -is [DateTime]) {
|
elseif ($attribute.Value -is [DateTime]) {
|
||||||
$headers.Add(($HttpHeaderPrefix + $attribute.Key), $attribute.Value.ToString("u"))
|
$headers.Add(($HttpHeaderPrefix + $attribute.Key), $attribute.Value.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ'))
|
||||||
}
|
}
|
||||||
elseif ($attribute.Value -is [Uri] -or $attribute.Value -is [int]) {
|
elseif ($attribute.Value -is [Uri] -or $attribute.Value -is [int]) {
|
||||||
$headers.Add(($HttpHeaderPrefix + $attribute.Key), $attribute.Value.ToString())
|
$headers.Add(($HttpHeaderPrefix + $attribute.Key), $attribute.Value.ToString())
|
||||||
|
|
|
@ -28,6 +28,35 @@ Describe "Client-Server Integration Tests" {
|
||||||
-ArgumentList $serverProcessArguments `
|
-ArgumentList $serverProcessArguments `
|
||||||
-PassThru `
|
-PassThru `
|
||||||
-NoNewWindow
|
-NoNewWindow
|
||||||
|
|
||||||
|
# Wait Server to Start
|
||||||
|
$serverPingRequest = `
|
||||||
|
New-CloudEvent `
|
||||||
|
-Id ([Guid]::NewGuid()) `
|
||||||
|
-Type $script:ServerPingType `
|
||||||
|
-Source $script:ClientSource | `
|
||||||
|
ConvertTo-HttpMessage `
|
||||||
|
-ContentMode Structured
|
||||||
|
|
||||||
|
$serverReady = $false
|
||||||
|
$maxRetries = 10
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest `
|
||||||
|
-Uri $testServerUrl `
|
||||||
|
-Headers $serverPingRequest.Headers `
|
||||||
|
-Body $serverPingRequest.Body | Out-Null
|
||||||
|
$serverReady = $true
|
||||||
|
} catch {
|
||||||
|
Write-Verbose "Wait CloudEvents HTTP Test Server to start"
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
$maxRetries--
|
||||||
|
}
|
||||||
|
} while (-not $serverReady -and $maxRetries -gt 0)
|
||||||
|
|
||||||
|
if ($maxRetries -eq 0) {
|
||||||
|
throw "CloudEvents HTTP Test Server failed to start."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
|
|
|
@ -77,22 +77,26 @@ param(
|
||||||
if ( $cloudEvent -ne $null ) {
|
if ( $cloudEvent -ne $null ) {
|
||||||
$Handler.Invoke($cloudEvent, $context.Response)
|
$Handler.Invoke($cloudEvent, $context.Response)
|
||||||
$context.Response.Close();
|
$context.Response.Close();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$context.Response.StatusCode = [int]([System.Net.HttpStatusCode]::BadRequest)
|
$context.Response.StatusCode = [int]([System.Net.HttpStatusCode]::BadRequest)
|
||||||
$context.Response.Close();
|
$context.Response.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Write-Error $_
|
Write-Error $_
|
||||||
$context.Response.StatusCode = [int]([System.Net.HttpStatusCode]::InternalServerError)
|
$context.Response.StatusCode = [int]([System.Net.HttpStatusCode]::InternalServerError)
|
||||||
$context.Response.Close();
|
$context.Response.Close();
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
$listener.Stop()
|
$listener.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$global:serverStopRequested = $false
|
$global:serverStopRequested = $false
|
||||||
while ( -not $global:serverStopRequested ) {
|
while ( -not $global:serverStopRequested ) {
|
||||||
|
try {
|
||||||
Start-HttpCloudEventListener -Url $ServerUrl -Handler {
|
Start-HttpCloudEventListener -Url $ServerUrl -Handler {
|
||||||
$requestCloudEvent = $args[0]
|
$requestCloudEvent = $args[0]
|
||||||
$response = $args[1]
|
$response = $args[1]
|
||||||
|
@ -115,11 +119,13 @@ while ( -not $global:serverStopRequested ) {
|
||||||
if ($requestCloudEventJsonData) {
|
if ($requestCloudEventJsonData) {
|
||||||
$cloudEvent = $cloudEvent | Set-CloudEventJsonData `
|
$cloudEvent = $cloudEvent | Set-CloudEventJsonData `
|
||||||
-Data $requestCloudEventJsonData
|
-Data $requestCloudEventJsonData
|
||||||
} elseif ($requestCloudEventXmlData) {
|
}
|
||||||
|
elseif ($requestCloudEventXmlData) {
|
||||||
$cloudEvent = $cloudEvent | Set-CloudEventXmlData `
|
$cloudEvent = $cloudEvent | Set-CloudEventXmlData `
|
||||||
-Data $requestCloudEventXmlData `
|
-Data $requestCloudEventXmlData `
|
||||||
-AttributesKeysInElementAttributes $false
|
-AttributesKeysInElementAttributes $false
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$requestCloudEventData = $requestCloudEvent | Read-CloudEventData
|
$requestCloudEventData = $requestCloudEvent | Read-CloudEventData
|
||||||
$cloudEvent = $cloudEvent | Set-CloudEventData `
|
$cloudEvent = $cloudEvent | Set-CloudEventData `
|
||||||
-Data $requestCloudEventData `
|
-Data $requestCloudEventData `
|
||||||
|
@ -138,7 +144,8 @@ while ( -not $global:serverStopRequested ) {
|
||||||
$response.OutputStream.Write($httpMessage.Body, 0, $httpMessage.Body.Length)
|
$response.OutputStream.Write($httpMessage.Body, 0, $httpMessage.Body.Length)
|
||||||
$response.StatusCode = [int]([System.Net.HttpStatusCode]::OK)
|
$response.StatusCode = [int]([System.Net.HttpStatusCode]::OK)
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
# No Content in all other cases
|
# No Content in all other cases
|
||||||
$response.StatusCode = [int]([System.Net.HttpStatusCode]::NoContent)
|
$response.StatusCode = [int]([System.Net.HttpStatusCode]::NoContent)
|
||||||
}
|
}
|
||||||
|
@ -148,4 +155,8 @@ while ( -not $global:serverStopRequested ) {
|
||||||
$global:serverStopRequested = $true
|
$global:serverStopRequested = $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Error $_
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,3 +8,4 @@ New-Variable -Option Constant -Scope 'script' -Name 'ServerSource' -Value 'ps:te
|
||||||
New-Variable -Option Constant -Scope 'script' -Name 'EchoBinaryType' -Value 'echo-binary'
|
New-Variable -Option Constant -Scope 'script' -Name 'EchoBinaryType' -Value 'echo-binary'
|
||||||
New-Variable -Option Constant -Scope 'script' -Name 'EchoStructuredType' -Value 'echo-structured'
|
New-Variable -Option Constant -Scope 'script' -Name 'EchoStructuredType' -Value 'echo-structured'
|
||||||
New-Variable -Option Constant -Scope 'script' -Name 'ServerStopType' -Value 'server-stop'
|
New-Variable -Option Constant -Scope 'script' -Name 'ServerStopType' -Value 'server-stop'
|
||||||
|
New-Variable -Option Constant -Scope 'script' -Name 'ServerPingType' -Value 'server-ping'
|
|
@ -30,7 +30,7 @@ Describe "ConvertFrom-HttpMessage Function Tests" {
|
||||||
'Content-Type' = @($expectedDataContentType, 'charset=utf-8')
|
'Content-Type' = @($expectedDataContentType, 'charset=utf-8')
|
||||||
'ce-specversion' = $expectedSpecVersion
|
'ce-specversion' = $expectedSpecVersion
|
||||||
'ce-type' = $expectedType
|
'ce-type' = $expectedType
|
||||||
'ce-time' = $expectedTime.ToString("u")
|
'ce-time' = $expectedTime.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')
|
||||||
'ce-id' = $expectedId
|
'ce-id' = $expectedId
|
||||||
'ce-source' = $expectedSource
|
'ce-source' = $expectedSource
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ Describe "ConvertFrom-HttpMessage Function Tests" {
|
||||||
$structuredJsonBody = @{
|
$structuredJsonBody = @{
|
||||||
'specversion' = $expectedSpecVersion
|
'specversion' = $expectedSpecVersion
|
||||||
'type' = $expectedType
|
'type' = $expectedType
|
||||||
'time' = $expectedTime.ToString("u")
|
'time' = $expectedTime.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')
|
||||||
'id' = $expectedId
|
'id' = $expectedId
|
||||||
'source' = $expectedSource
|
'source' = $expectedSource
|
||||||
'datacontenttype' = $expectedDataContentType
|
'datacontenttype' = $expectedDataContentType
|
||||||
|
|
|
@ -16,7 +16,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
|
||||||
$expectedType = 'test'
|
$expectedType = 'test'
|
||||||
$expectedSource = 'urn:test'
|
$expectedSource = 'urn:test'
|
||||||
$expectedId = 'test-id-1'
|
$expectedId = 'test-id-1'
|
||||||
$expectedTime = Get-Date -Year 2021 -Month 1 -Day 18 -Hour 12 -Minute 30 -Second 0
|
$expectedTime = Get-Date -Year 2021 -Month 1 -Day 18 -Hour 12 -Minute 30 -Second 0 -Millisecond 0
|
||||||
$expectedDataContentType = 'application/json'
|
$expectedDataContentType = 'application/json'
|
||||||
|
|
||||||
$cloudEvent = New-CloudEvent `
|
$cloudEvent = New-CloudEvent `
|
||||||
|
@ -44,7 +44,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
|
||||||
$actual.Headers['ce-source'] | Should -Be $expectedSource
|
$actual.Headers['ce-source'] | Should -Be $expectedSource
|
||||||
$actual.Headers['ce-specversion'] | Should -Be $expectedSpecVersion
|
$actual.Headers['ce-specversion'] | Should -Be $expectedSpecVersion
|
||||||
$actual.Headers['ce-type'] | Should -Be $expectedType
|
$actual.Headers['ce-type'] | Should -Be $expectedType
|
||||||
$actual.Headers['ce-time'] | Should -Be '2021-01-18 12:30:00Z'
|
$actual.Headers['ce-time'] | Should -Be ($expectedTime.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ'))
|
||||||
$actual.Headers['ce-id'] | Should -Be $expectedId
|
$actual.Headers['ce-id'] | Should -Be $expectedId
|
||||||
|
|
||||||
## Assert Body
|
## Assert Body
|
||||||
|
@ -110,7 +110,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
|
||||||
$expectedType = 'test'
|
$expectedType = 'test'
|
||||||
$expectedSource = 'urn:test'
|
$expectedSource = 'urn:test'
|
||||||
$expectedId = 'test-id-1'
|
$expectedId = 'test-id-1'
|
||||||
$expectedTime = Get-Date -Year 2021 -Month 1 -Day 18 -Hour 12 -Minute 30 -Second 0
|
$expectedTime = Get-Date -Year 2021 -Month 1 -Day 18 -Hour 12 -Minute 30 -Second 0 -Millisecond 0
|
||||||
$expectedDataContentType = 'application/json'
|
$expectedDataContentType = 'application/json'
|
||||||
|
|
||||||
$cloudEvent = New-CloudEvent `
|
$cloudEvent = New-CloudEvent `
|
||||||
|
@ -141,7 +141,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
|
||||||
$actual.Headers['ce-source'] | Should -Be $expectedSource
|
$actual.Headers['ce-source'] | Should -Be $expectedSource
|
||||||
$actual.Headers['ce-specversion'] | Should -Be $expectedSpecVersion
|
$actual.Headers['ce-specversion'] | Should -Be $expectedSpecVersion
|
||||||
$actual.Headers['ce-type'] | Should -Be $expectedType
|
$actual.Headers['ce-type'] | Should -Be $expectedType
|
||||||
$actual.Headers['ce-time'] | Should -Be '2021-01-18 12:30:00Z'
|
$actual.Headers['ce-time'] | Should -Be ($expectedTime.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ'))
|
||||||
$actual.Headers['ce-id'] | Should -Be $expectedId
|
$actual.Headers['ce-id'] | Should -Be $expectedId
|
||||||
|
|
||||||
## Assert Body
|
## Assert Body
|
||||||
|
|
Loading…
Reference in New Issue