Skip to content

Commit

Permalink
Added returnvalue to BlobStorage functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Mar 8, 2024
1 parent ee5eab3 commit a80223e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Updated logging to new function in Add-ModulesToBlobStorage and Get-ModulesFromBlobStorage
- Updated Add-ModulesToBlobStorage and Get-ModulesFromBlobStorage to return a boolean with
the result of the operation

## [0.2.3] - 2024-03-05

- Fixed issue in Set-PipelineYaml where an exception was thrown when the Defaults
Expand Down
6 changes: 5 additions & 1 deletion source/Public/Add-ModulesToBlobStorage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function Add-ModulesToBlobStorage
Add-ModulesToBlobStorage -ResourceGroupName 'MyResourceGroup' -StorageAccountName 'MyStorageAccount' -ContainerName 'MyContainer'
#>
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
# [Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -105,6 +106,9 @@ function Add-ModulesToBlobStorage
}
else
{
Write-Log -Object '[ERROR] Dependencies\Manifest.psd1 file not found'
Write-Log -Object '[ERROR] Dependencies\Manifest.psd1 file not found' -Failure
return $false
}

return $true
}
5 changes: 4 additions & 1 deletion source/Public/Get-ModulesFromBlobStorage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function Get-ModulesFromBlobStorage
Get-ModulesFromBlobStorage -ResourceGroupName 'MyResourceGroup' -StorageAccountName 'MyStorageAccount' -ContainerName 'MyContainer' -Version 1.23.530.1
#>
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -66,7 +67,8 @@ function Get-ModulesFromBlobStorage

if ($null -eq $blobContent)
{
Write-Log -Object "[ERROR] No files found that match the pattern: '$prefix'"
Write-Log -Object "[ERROR] No files found that match the pattern: '$prefix'" -Failure
return $false
}
else
{
Expand Down Expand Up @@ -109,4 +111,5 @@ function Get-ModulesFromBlobStorage
Remove-Item -Path $extractPath -Recurse -Confirm:$false
Remove-Item -Path $destination -Recurse -Confirm:$false
}
return $true
}
2 changes: 1 addition & 1 deletion source/Public/Set-ADOEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function Set-ADOEnvironment
}
else
{
Write-Log -Object ' Error while retrieving Environment Checks'
Write-Log -Object ' Error while retrieving Environment Checks' -Failure
return $false
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/Public/Add-ModulesToBlobStorage.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ Describe Add-ModulesToBlobStorage {
}

It 'Upload successful' {
Add-ModulesToBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' | Should -Invoke 'Set-AzStorageBlobContent'
Add-ModulesToBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' | Should -Be $true
Should -Invoke 'Set-AzStorageBlobContent'
}
}

Expand All @@ -98,7 +99,8 @@ Describe Add-ModulesToBlobStorage {
}

It 'File does not exist' {
Add-ModulesToBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' | Should -Invoke 'Save-Module' -ModuleName 'M365DSCTools' -Times 0
Add-ModulesToBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' | Should -Be $false
Should -Invoke 'Save-Module' -ModuleName 'M365DSCTools' -Times 0
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/Public/Get-ModulesFromBlobStorage.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Describe Get-ModulesFromBlobStorage {
}

It 'Returns a single object' {
Get-ModulesFromBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' -Version '1.23.530.1' | Should -Invoke 'Copy-Item' -ModuleName 'M365DSCTools' -Times 1
Get-ModulesFromBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' -Version '1.23.530.1' | Should -Be $true
Should -Invoke 'Copy-Item' -ModuleName 'M365DSCTools' -Times 1
}
}

Expand All @@ -75,7 +76,8 @@ Describe Get-ModulesFromBlobStorage {
}

It 'Returns a single object' {
Get-ModulesFromBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' -Version '1.23.530.1' | Should -Invoke 'Copy-Item' -ModuleName 'M365DSCTools' -Times 0
Get-ModulesFromBlobStorage -ResourceGroupName 'M365DscResources' -StorageAccountName 'M365DscStorageAccount' -ContainerName 'M365DscContainer' -Version '1.23.530.1' | Should -Be $false
Should -Invoke 'Copy-Item' -ModuleName 'M365DSCTools' -Times 0
}
}
}
Expand Down

0 comments on commit a80223e

Please sign in to comment.