generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add az fileshare storage integration tests with real az resourc…
…es (#180) * test: add az fileshare storage integration tests with real az resources * pr-fix: don't use resource group for creating az fileshare * pr-fix: update w/o additional az fileshare setup * pr-add: integration test for az fileshare w existing folder * pr-fix: use guid to generate unique file shares * pr-fix: use guid to generate unique file shares * pr-fix: use correct fileshare name * pr-fix: still publish test results even when when test suite fails * pr-add: integration test for uploading to az fileshare * pr-add: integration test for non-existing az fileshare * pr-fix: update with passing storage context * pr-fix: update with correct assertion and arg names * pr-fix: update with correct test args + revisit fileshare folder creation script * pr-fix: update with forced fileshare deletion + correct mocked assertions * pr-fix: update with correct ps storage account * pr-fix: update with simpler integration test teardown * pr-fix: unit & integration tests final * Update run-pester-tests.yml * Update Arcus.Scripting.Storage.FileShare.tests.ps1 * pr-fix: change filestorage feature docs with updated logging
- Loading branch information
1 parent
4c1ed00
commit b08c6e9
Showing
8 changed files
with
231 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-32 Bytes
(100%)
src/Arcus.Scripting.Storage.FileShare/Arcus.Scripting.Storage.FileShare.psd1
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Storage.FileShare.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
Import-Module Az.Storage | ||
Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.Storage.FileShare -ErrorAction Stop | ||
|
||
InModuleScope Arcus.Scripting.Storage.FileShare { | ||
Describe "Arcus Azure FileShare storage integration tests" { | ||
BeforeEach { | ||
$config = & $PSScriptRoot\Load-JsonAppsettings.ps1 -fileName "appsettings.json" | ||
& $PSScriptRoot\Connect-AzAccountFromConfig.ps1 -config $config | ||
$guid = [System.Guid]::NewGuid() | ||
$fileShareName = "arcus-scripting-fileshare-$guid" | ||
$storageAccount = Get-AzStorageAccount -ResourceGroupName $config.Arcus.ResourceGroupName -Name $config.Arcus.Storage.StorageAccount.Name | ||
New-AzStorageShare -Context $storageAccount.Context -Name $fileShareName | ||
} | ||
Context "Create Azure FileShare storage folder" { | ||
It "Creates a new Azure FileShare storage folder" { | ||
# Arrange | ||
$folderName = "new-arcus-fileshare-folder" | ||
|
||
# Act | ||
Create-AzFileShareStorageFolder ` | ||
-ResourceGroupName $config.Arcus.ResourceGroupName ` | ||
-StorageAccountName $config.Arcus.Storage.StorageAccount.Name ` | ||
-FileShareName $fileShareName ` | ||
-FolderName $folderName | ||
|
||
# Assert | ||
Get-AzStorageFile -ShareName $fileShareName -Context $storageAccount.Context | | ||
where { $_.GetType().Name -eq "AzureStorageFileDirectory" } | | ||
% { $_.Name } | | ||
Should -Contain $folderName | ||
} | ||
It "Doesn't create a new Azure FileShare storage folder when already exists" { | ||
# Arrange | ||
$folderName = "already-existing-arcus-fileshare-folder" | ||
New-AzStorageDirectory -Context $storageAccount.Context -ShareName $fileShareName -Path $folderName | ||
|
||
# Act | ||
Create-AzFileShareStorageFolder ` | ||
-ResourceGroupName $config.Arcus.ResourceGroupName ` | ||
-StorageAccountName $config.Arcus.Storage.StorageAccount.Name ` | ||
-FileShareName $fileShareName ` | ||
-FolderName $folderName | ||
|
||
# Assert | ||
Get-AzStorageFile -ShareName $fileShareName -Context $storageAccount.Context | | ||
where { $_.GetType().Name -eq "AzureStorageFileDirectory" } | | ||
% { $_.Name } | | ||
Should -Contain $folderName | ||
} | ||
} | ||
Context "Copy files into Azure FileShare storage folder" { | ||
It "Uploads file into existing Azure FileShare storage" { | ||
# Arrange | ||
$folderName = "uploaded-arcus-fileshare-folder" | ||
New-AzStorageDirectory -Context $storageAccount.Context -ShareName $fileShareName -Path $folderName | ||
|
||
# Act | ||
Copy-AzFileShareStorageFiles ` | ||
-ResourceGroupName $config.Arcus.ResourceGroupName ` | ||
-StorageAccountName $config.Arcus.Storage.StorageAccount.Name ` | ||
-FileShareName $fileShareName ` | ||
-SourceFolderPath "$PSScriptRoot\Blobs" ` | ||
-DestinationFolderName $folderName | ||
|
||
# Assert | ||
$tempLocation = "$PSScriptRoot\arcus.png" | ||
try { | ||
Get-AzStorageFileContent ` | ||
-Context $storageAccount.Context ` | ||
-ShareName $fileShareName ` | ||
-Path "$folderName/arcus.png" ` | ||
-Destination $tempLocation -Force | ||
$file = Get-Item $tempLocation | ||
$file.Length | Should -BeGreaterThan 0 | ||
} finally { | ||
Remove-Item $tempLocation -Force | ||
} | ||
} | ||
It "Uploads file into non-existing Azure FileShare storage" { | ||
# Arrange | ||
$folderName = "non-existing-arcus-fileshare-folder" | ||
$nonExistingFileShareName = "non-existing-fileshare-storage" | ||
|
||
# Act / Assert | ||
{ Copy-AzFileShareStorageFiles ` | ||
-ResourceGroupName $config.Arcus.ResourceGroupName ` | ||
-StorageAccountName $config.Arcus.Storage.StorageAccount.Name ` | ||
-FileShareName $nonExistingFileShareName ` | ||
-SourceFolderPath "$PSScriptRoot\Blobs" ` | ||
-DestinationFolderName $folderName } | | ||
Should -Throw | ||
} | ||
} | ||
AfterEach { | ||
Remove-AzStorageShare -Name $fileShareName -Context $storageAccount.Context -IncludeAllSnapshot -Force | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Arcus.Scripting.Tests.Integration/Load-JsonAppsettings.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
param( | ||
[string]$fileName | ||
) | ||
|
||
$filePath = "$PSScriptRoot\$fileName" | ||
[string]$appsettings = Get-Content $filePath | ||
return $config = ConvertFrom-Json $appsettings |
Oops, something went wrong.