From f41fe6c105af0445c1109cede07ad6e9705a86c6 Mon Sep 17 00:00:00 2001 From: "Grace Huang (from Dev Box)" Date: Tue, 30 Jan 2024 12:24:40 -0500 Subject: [PATCH] more tests --- .../custom/New-AzSupportFileAndUpload.ps1 | 16 ++++---- .../test/New-AzSupportFileAndUpload.Tests.ps1 | 9 ++++- ...pportTicketNameAvailability.Recording.json | 38 +++++++++++++++++++ ...-AzSupportTicketNameAvailability.Tests.ps1 | 5 ++- ...ubscriptionNameAvailability.Recording.json | 38 +++++++++++++++++++ ...tsNoSubscriptionNameAvailability.Tests.ps1 | 5 ++- src/Support/Support.Autorest/test/env.json | 6 +-- .../Support.Autorest/test/files/test.txt | 1 + 8 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Recording.json create mode 100644 src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Recording.json create mode 100644 src/Support/Support.Autorest/test/files/test.txt diff --git a/src/Support/Support.Autorest/custom/New-AzSupportFileAndUpload.ps1 b/src/Support/Support.Autorest/custom/New-AzSupportFileAndUpload.ps1 index ebbe83f3569b..b25de32a70e3 100644 --- a/src/Support/Support.Autorest/custom/New-AzSupportFileAndUpload.ps1 +++ b/src/Support/Support.Autorest/custom/New-AzSupportFileAndUpload.ps1 @@ -129,7 +129,7 @@ param( process { $ErrorActionPreference = 'Stop' - Write-Output "file path: " $FilePath + #Write-Output "file path: " + $FilePath $MaxChunkSize = 2.5 * 1024 * 1024 #2.5 MB $MaxFileSize = 5 * 1024 * 1024 #5 MB $FileContentBytes = Get-Content -Path $FilePath -Raw @@ -142,15 +142,15 @@ process { throw "File size is greater than the maximum file size of 5 MB" } $ChunkSize = If($FileSize -gt $MaxChunkSize) {$MaxChunkSize} Else {$FileSize} - Write-Output "Length of byte array: " $FileSize - Write-Output "Max chunk size: " $MaxChunkSize - Write-Output "Chunk Size: " $ChunkSize + # Write-Output "Length of byte array: " $FileSize + # Write-Output "Max chunk size: " $MaxChunkSize + # Write-Output "Chunk Size: " $ChunkSize $NumberOfChunks = [int][Math]::Floor($FileSize / $ChunkSize); If($FileSize % $ChunkSize -gt 0) { $NumberOfChunks++ } - Write-Output "Number of chunks: " $NumberOfChunks + # Write-Output "Number of chunks: " $NumberOfChunks New-AzSupportFile -SubscriptionId $SubscriptionId -Name $Name -WorkspaceName $WorkspaceName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks @@ -162,9 +162,9 @@ process { # $FileContent = [convert]::ToBase64String((Get-Content -path $FilePath -Encoding byte)) while($chunkIndex -lt $NumberOfChunks){ - Write-Output "chunk index: " + $chunkIndex - Write-Output "start index: " + $startIndex - Write-Output "end index: " + $endIndex + # Write-Output "chunk index: " + $chunkIndex + # Write-Output "start index: " + $startIndex + # Write-Output "end index: " + $endIndex $FileContent = [convert]::ToBase64String($FileContentByteArray[$startIndex..$endIndex]) Invoke-AzSupportUploadFile -SubscriptionId $SubscriptionId -FileName $Name -FileWorkspaceName $WorkspaceName -ChunkIndex $chunkIndex -Content $FileContent diff --git a/src/Support/Support.Autorest/test/New-AzSupportFileAndUpload.Tests.ps1 b/src/Support/Support.Autorest/test/New-AzSupportFileAndUpload.Tests.ps1 index 99fd042ba94c..40b23b15c345 100644 --- a/src/Support/Support.Autorest/test/New-AzSupportFileAndUpload.Tests.ps1 +++ b/src/Support/Support.Autorest/test/New-AzSupportFileAndUpload.Tests.ps1 @@ -15,7 +15,12 @@ if(($null -eq $TestName) -or ($TestName -contains 'New-AzSupportFileAndUpload')) } Describe 'New-AzSupportFileAndUpload' { - It 'CreateExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'CreateExpanded' { + Write-Host "current path: " + $currentPath + Write-Host "ps script root: " + $PSScriptRoot + $testFilePath = Join-Path $PSScriptRoot files test.txt + Write-Host "test file path: " + $testFilePath + $file = New-AzSupportFileAndUpload -Name "test.txt" -WorkspaceName $env.FileWorkspaceNameSubscription -FilePath $testFilePath + $file.Name | Should -Be "test.txt" } } diff --git a/src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Recording.json b/src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Recording.json new file mode 100644 index 000000000000..8336a09cf17e --- /dev/null +++ b/src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Recording.json @@ -0,0 +1,38 @@ +{ + "Test-AzSupportTicketNameAvailability+[NoContext]+CheckExpanded+$POST+https://management.azure.com/subscriptions/4df09db9-7a7e-450b-8f88-00fb97c277bd/providers/Microsoft.Support/checkNameAvailability?api-version=2022-09-01-preview+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://management.azure.com/subscriptions/4df09db9-7a7e-450b-8f88-00fb97c277bd/providers/Microsoft.Support/checkNameAvailability?api-version=2022-09-01-preview", + "Content": "{\r\n \"name\": \"test-ps-42dbecba-4472-40af-9db4-1c0f1e9780a1\",\r\n \"type\": \"Microsoft.Support/supportTickets\"\r\n}", + "isContentBase64": false, + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "109" ] + } + }, + "Response": { + "StatusCode": 200, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Pragma": [ "no-cache" ], + "X-Content-Type-Options": [ "nosniff" ], + "Strict-Transport-Security": [ "max-age=31536000; includeSubDomains" ], + "Server": [ "Kestrel" ], + "x-ms-ratelimit-remaining-subscription-writes": [ "1199" ], + "x-ms-request-id": [ "2f30b178-d575-4095-9ee7-4ac5f905706f" ], + "x-ms-correlation-request-id": [ "2f30b178-d575-4095-9ee7-4ac5f905706f" ], + "x-ms-routing-request-id": [ "EASTUS:20240130T171835Z:2f30b178-d575-4095-9ee7-4ac5f905706f" ], + "Date": [ "Tue, 30 Jan 2024 17:18:35 GMT" ] + }, + "ContentHeaders": { + "Content-Length": [ "22" ], + "Content-Type": [ "application/json; charset=utf-8" ], + "Expires": [ "-1" ] + }, + "Content": "{\"nameAvailable\":true}", + "isContentBase64": false + } + } +} \ No newline at end of file diff --git a/src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Tests.ps1 b/src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Tests.ps1 index ffd0b95d403f..d4d844c099cf 100644 --- a/src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Tests.ps1 +++ b/src/Support/Support.Autorest/test/Test-AzSupportTicketNameAvailability.Tests.ps1 @@ -15,8 +15,9 @@ if(($null -eq $TestName) -or ($TestName -contains 'Test-AzSupportTicketNameAvail } Describe 'Test-AzSupportTicketNameAvailability' { - It 'CheckExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'CheckExpanded' { + $result = Test-AzSupportTicketNameAvailability -Name "test-ps-$(New-Guid)" -Type "Microsoft.Support/supportTickets"-SubscriptionId $env.SubscriptionId + $result.NameAvailable | Should -Be $true } It 'Check' -skip { diff --git a/src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Recording.json b/src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Recording.json new file mode 100644 index 000000000000..3f622f760e71 --- /dev/null +++ b/src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Recording.json @@ -0,0 +1,38 @@ +{ + "Test-AzSupportTicketsNoSubscriptionNameAvailability+[NoContext]+CheckExpanded+$POST+https://management.azure.com/providers/Microsoft.Support/checkNameAvailability?api-version=2022-09-01-preview+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://management.azure.com/providers/Microsoft.Support/checkNameAvailability?api-version=2022-09-01-preview", + "Content": "{\r\n \"name\": \"test-ps-f0f0df36-66f3-4f4e-9686-80a68bb9d53d\",\r\n \"type\": \"Microsoft.Support/supportTickets\"\r\n}", + "isContentBase64": false, + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "109" ] + } + }, + "Response": { + "StatusCode": 200, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Pragma": [ "no-cache" ], + "X-Content-Type-Options": [ "nosniff" ], + "Strict-Transport-Security": [ "max-age=31536000; includeSubDomains" ], + "Server": [ "Kestrel" ], + "x-ms-ratelimit-remaining-tenant-writes": [ "1199" ], + "x-ms-request-id": [ "746f8be3-9ba4-4323-93fa-3567dff84f3f" ], + "x-ms-correlation-request-id": [ "746f8be3-9ba4-4323-93fa-3567dff84f3f" ], + "x-ms-routing-request-id": [ "EASTUS:20240130T172214Z:746f8be3-9ba4-4323-93fa-3567dff84f3f" ], + "Date": [ "Tue, 30 Jan 2024 17:22:14 GMT" ] + }, + "ContentHeaders": { + "Content-Length": [ "22" ], + "Content-Type": [ "application/json; charset=utf-8" ], + "Expires": [ "-1" ] + }, + "Content": "{\"nameAvailable\":true}", + "isContentBase64": false + } + } +} \ No newline at end of file diff --git a/src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Tests.ps1 b/src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Tests.ps1 index 61df07f6abf0..9fe486df7604 100644 --- a/src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Tests.ps1 +++ b/src/Support/Support.Autorest/test/Test-AzSupportTicketsNoSubscriptionNameAvailability.Tests.ps1 @@ -15,8 +15,9 @@ if(($null -eq $TestName) -or ($TestName -contains 'Test-AzSupportTicketsNoSubscr } Describe 'Test-AzSupportTicketsNoSubscriptionNameAvailability' { - It 'CheckExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'CheckExpanded' { + $result = Test-AzSupportTicketsNoSubscriptionNameAvailability -Name "test-ps-$(New-Guid)" -Type "Microsoft.Support/supportTickets" + $result.NameAvailable | Should -Be $true } It 'Check' -skip { diff --git a/src/Support/Support.Autorest/test/env.json b/src/Support/Support.Autorest/test/env.json index 040901da8987..a17cc5e761f9 100644 --- a/src/Support/Support.Autorest/test/env.json +++ b/src/Support/Support.Autorest/test/env.json @@ -1,8 +1,8 @@ { - "BillingProblemClassificationId": "d0f16bf7-e011-3f3b-1c26-3147f84e0896", "BillingServiceId": "517f2da6-78fd-0498-4e22-ad26996b1dfc", + "BillingProblemClassificationId": "d0f16bf7-e011-3f3b-1c26-3147f84e0896", "Tenant": "d71d46f6-114f-4d2a-81c9-8fc86ba8801c", - "FileWorkspaceNameNoSubscription": "test-ps-43ad6585-c0ac-4a13-8d0e-bb633b8b1db3", + "FileWorkspaceNameNoSubscription": "test-ps-94021760-e8a2-4995-85d4-13e6b443eddb", "SubscriptionId": "4df09db9-7a7e-450b-8f88-00fb97c277bd", - "FileWorkspaceNameSubscription": "test-ps-d4adfb8c-f15c-48de-a0b0-8da419bfe51d" + "FileWorkspaceNameSubscription": "test-ps-515d6c7e-beb8-4617-8325-cfd236c4bc5b" } diff --git a/src/Support/Support.Autorest/test/files/test.txt b/src/Support/Support.Autorest/test/files/test.txt new file mode 100644 index 000000000000..30d74d258442 --- /dev/null +++ b/src/Support/Support.Autorest/test/files/test.txt @@ -0,0 +1 @@ +test \ No newline at end of file