Skip to content

Commit 8d70e40

Browse files
committed
Because we want returns only 3 major properties to be returned when use -NoWait parameter
1 parent d317037 commit 8d70e40

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

source/Private/Test-FabricApiResponse.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ function Test-FabricApiResponse {
7474
if ($NoWait) {
7575
Write-Message -Message "NoWait parameter is set. Operation ID: $operationId" -Level Info
7676
Write-Message -Message "Run to check the progress: Get-FabricLongRunningOperationResult -operationId '$operationId'" -Level Verbose
77-
return $responseHeader
77+
return [PSCustomObject]@{
78+
Location = $responseHeader["Location"]
79+
RetryAfter = $responseHeader["Retry-After"]
80+
OperationId = $responseHeader["x-ms-operation-id"]
81+
}
7882
}
7983

8084
Write-Message -Message "[Test-FabricApiResponse] Operation ID: '$operationId'" -Level Debug

tests/Unit/Test-FabricApiResponse.Tests.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ Describe "Test-FabricApiResponse - StatusCode Handling" -Tag "UnitTests" {
5555

5656
BeforeAll {
5757
# Generate a random GUID for x-ms-operation-id
58-
$script:responseHeader = @{ "x-ms-operation-id" = [guid]::NewGuid().ToString() }
58+
$script:responseHeader = @{
59+
"x-ms-operation-id" = [guid]::NewGuid().ToString()
60+
"Location" = "https://api.fabric.microsoft.com/v1/operations/$([guid]::NewGuid().ToString())"
61+
"Retry-After" = 30
62+
}
5963
$script:response = @{ "foo" = "bar" }
6064
}
6165

@@ -91,10 +95,18 @@ Describe "Test-FabricApiResponse - StatusCode Handling" -Tag "UnitTests" {
9195
Should -Invoke Get-FabricLongRunningOperationResult -Exactly 1
9296
}
9397

94-
It "Returns responseHeader when statusCode is 202 and -NoWait is specified" {
98+
It "Returns PSCustomObject with 3 properties when statusCode is 202 and -NoWait is specified" {
9599
$script:statusCode = 202
96100
$result = Test-FabricApiResponse -Response $script:response -NoWait
97-
$result | Should -Be $script:responseHeader
101+
102+
$expected = [PSCustomObject]@{
103+
Location = $script:responseHeader.Location
104+
RetryAfter = $script:responseHeader.'Retry-After'
105+
OperationId = $script:responseHeader.'x-ms-operation-id'
106+
}
107+
$result.Location | Should -Be $expected.Location
108+
$result.RetryAfter | Should -Be $expected.RetryAfter
109+
$result.OperationId | Should -Be $expected.OperationId
98110
}
99111

100112
It "Throws when statusCode is not 200, 201, or 202" {

0 commit comments

Comments
 (0)