diff --git a/build/templates/run-pester-tests.yml b/build/templates/run-pester-tests.yml index 09ad0390..bc922b5e 100644 --- a/build/templates/run-pester-tests.yml +++ b/build/templates/run-pester-tests.yml @@ -2,6 +2,12 @@ parameters: projectName: '' steps: + - pwsh: 'wget -O - https://aka.ms/install-powershell.sh | sudo bash' + displayName: 'Update Powershell on Linux' + condition: eq( variables['Agent.OS'], 'Linux' ) + - powershell: 'Invoke-Expression -Command "& { $(Invoke-RestMethod -Uri ''https://aka.ms/install-powershell.ps1'') } -UseMSI -quiet" ' + displayName: 'Update Powershell on Windows' + condition: eq( variables['Agent.OS'], 'Windows_NT' ) - bash: | if [ -z "$PROJECT_NAME" ]; then echo "##vso[task.logissue type=error;]Missing template parameter \"projectName\"" @@ -37,7 +43,7 @@ steps: Install-Module -Name Microsoft.Graph.Applications -Force -SkipPublisherCheck -MaximumVersion 1.15.0 Write-Host "Done installing, start importing modules" displayName: 'Install Pester test framework and Az required modules' - - powershell: | + - pwsh: | Import-Module ./src/Arcus.Scripting.Security Get-ChildItem -Path ./src -Filter *.psm1 -Recurse -Exclude "*Arcus.Scripting.Security*", "*.All.psm1" | % { Write-Host "Import $($_.DirectoryName) module" diff --git a/docs/preview/03-Features/powershell/azure-storage/azure-storage-table.md b/docs/preview/03-Features/powershell/azure-storage/azure-storage-table.md index 492b72a8..79e4d039 100644 --- a/docs/preview/03-Features/powershell/azure-storage/azure-storage-table.md +++ b/docs/preview/03-Features/powershell/azure-storage/azure-storage-table.md @@ -53,3 +53,81 @@ PS> Create-AzStorageTable ` # Failed to re-create the Azure storage table 'products' in Azure storage account 'admin', retrying in 5 seconds... # Azure storage table 'products' created in Azure storage account 'admin' ``` + + +## Set the entities in a table of an Azure Storage Account + +Deletes all entities of a specified table in an Azure Storage Account and creates new entities based on a configuration file. + +| Parameter | Mandatory | Description | +| ---------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------- | +| `ResourceGroupName` | yes | The resource group where the Azure Storage Account is located | +| `StorageAccountName` | yes | The name of the Azure Storage Account that contains the table | +| `TableName` | yes | The name of the table in which the entities should be set | +| `ConfigurationFile` | yes | Path to the JSON Configuration file containing all the entities to be set | + +**Configuration File** + +The configuration file is a simple JSON file that contains all of the entities that should be set on the specified table, the JSON file consists of an array of JSON objects (= your entities). Each object contains simple name-value pairs (string-string). + +Defining the PartitionKey and/or RowKey are optional, if not provided a random GUID will be set for these. + + The file needs to adhere to the following JSON schema: + +``` json +{ + "definitions": {}, + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://scripting.arcus-azure.net/Features/powershell/azure-storage/azure-storage-table/config.json", + "type": "array", + "title": "The configuration JSON schema", + "items": [{ + "type": "object", + "patternProperties": { + "^.*$": { + "anyOf": [{ + "type": "string" + }, { + "type": "null" + } + ] + } + }, + "additionalProperties": false + } + ] +} +``` + +**Example Configuration File** + +```json +[ + { + "PartitionKey": "SystemA", + "RowKey": "100", + "ReadPath": "/home/in", + "ReadIntervalInSeconds": "30" + }, + { + "PartitionKey": "SystemA", + "RowKey": "200", + "ReadPath": "/data/in", + "ReadIntervalInSeconds": "10", + "HasSubdirectories": "true" + } +] +``` + +**Example** + +```powershell +PS> Set-AzTableStorageEntities ` +-ResourceGroupName "someresourcegroup" ` +-StorageAccountName "somestorageaccount" ` +-TableName "sometable" ` +-ConfigurationFile ".\config.json" +# Deleting all existing entities in Azure storage table 'sometable' for Azure storage account 'somestorageaccount' in resource group 'someresourcegroup'... +# Successfully deleted all existing entities in Azure storage table 'sometable' for Azure storage account 'somestorageaccount' in resource group 'someresourcegroup' +# Successfully added all entities in Azure storage table 'sometable' for Azure storage account 'somestorageaccount' in resource group 'someresourcegroup' +``` diff --git a/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psd1 b/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psd1 index 272375b7..1f0469a9 100644 Binary files a/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psd1 and b/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psd1 differ diff --git a/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psm1 b/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psm1 index e9fe2bca..db65e173 100644 --- a/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psm1 +++ b/src/Arcus.Scripting.Storage.Table/Arcus.Scripting.Storage.Table.psm1 @@ -51,4 +51,48 @@ function Create-AzStorageTable { } } -Export-ModuleMember -Function Create-AzStorageTable \ No newline at end of file +Export-ModuleMember -Function Create-AzStorageTable + + + +<# + .Synopsis + Sets the entities in a specified table storage. + + .Description + Sets (Delete & Add) the entities in a specified table storage to the values specified in a (JSON) configuration file. + + .Parameter ResourceGroupName + The resource group where the Azure Storage Account is located. + + .Parameter StorageAccountName + The name of the Azure Storage Account which holds the Azure table storage. + + .Parameter TableName + The name of the table on the Azure Storage Account. + + .Parameter ConfigurationFile + The Configuration File (JSON) specifying the entities that have to be set in the table storage. The JSON file has a single property "entities" which is an array of objects. + + .Parameter RetryIntervalSeconds + The optional amount of seconds to wait each retry-run when a failure occures during the re-creating process. + + .Parameter MaxRetryCount + The optional maximum amount of retry-runs should happen when a failure occurs during the re-creating process. +#> +function Set-AzTableStorageEntities { + param( + [Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of resource group is required"), + [Parameter(Mandatory = $true)][string] $StorageAccountName = $(throw "Name of Azure storage account is required"), + [Parameter(Mandatory = $true)][string] $TableName = $(throw "Name of Azure table is required"), + [Parameter(Mandatory = $true)][string] $ConfigurationFile = $(throw "Path to the configuration file is required") + ) + + . $PSScriptRoot\Scripts\Set-AzTableStorageEntities.ps1 ` + -ResourceGroupName $ResourceGroupName ` + -StorageAccountName $StorageAccountName ` + -TableName $TableName ` + -ConfigurationFile $ConfigurationFile +} + +Export-ModuleMember -Function Set-AzTableStorageEntities \ No newline at end of file diff --git a/src/Arcus.Scripting.Storage.Table/Scripts/Set-AzTableStorageEntities.ps1 b/src/Arcus.Scripting.Storage.Table/Scripts/Set-AzTableStorageEntities.ps1 new file mode 100644 index 00000000..437b80c2 --- /dev/null +++ b/src/Arcus.Scripting.Storage.Table/Scripts/Set-AzTableStorageEntities.ps1 @@ -0,0 +1,93 @@ +param( + [Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Name of resource group is required"), + [Parameter(Mandatory = $true)][string] $StorageAccountName = $(throw "Name of Azure storage account is required"), + [Parameter(Mandatory = $true)][string] $TableName = $(throw "Name of Azure table is required"), + [Parameter(Mandatory = $true)][string] $ConfigurationFile = $(throw "Path to the configuration file is required") +) + +if (-not (Test-Path -Path $ConfigurationFile)) { + throw "Cannot re-create entities based on JSON configuration file because no file was found at: '$ConfigurationFile'" +} +if ((Get-Content -Path $ConfigurationFile -Raw) -eq $null) { + throw "Cannot re-create entities based on JSON configuration file because the file is empty." +} + +$schema = @' +{ + "definitions": {}, + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://scripting.arcus-azure.net/Features/powershell/azure-storage/azure-storage-table/config.json", + "type": "array", + "title": "The configuration JSON schema", + "items": [{ + "type": "object", + "patternProperties": { + "^.*$": { + "anyOf": [{ + "type": "string" + }, { + "type": "null" + } + ] + } + }, + "additionalProperties": false + } + ] +} +'@ + +if (-not (Get-Content -Path $ConfigurationFile -Raw | Test-Json -Schema $schema -ErrorAction SilentlyContinue)) { + throw "Cannot re-create entities based on JSON configuration file because the file does not contain a valid JSON configuration file." +} + +Write-Verbose "Retrieving Azure storage account context for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'..." +$storageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName +if ($storageAccount -eq $null) { + throw "Retrieving Azure storage account context for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName' failed." +} +$ctx = $storageAccount.Context +Write-Verbose "Azure storage account context has been retrieved for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'" + +Write-Verbose "Retrieving Azure storage table '$TableName' for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'..." +$storageTable = Get-AzStorageTable -Name $TableName -Context $ctx +if ($storageTable -eq $null) { + throw "Retrieving Azure storage table '$TableName' for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName' failed." +} +$cloudTable = ($storageTable).CloudTable +Write-Verbose "Azure storage table '$TableName' has been retrieved for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'" + +Write-Host "Deleting all existing entities in Azure storage table '$TableName' for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'..." +$entitiesToDelete = Get-AzTableRow -table $cloudTable +$deletedEntities = $entitiesToDelete | Remove-AzTableRow -table $cloudTable +Write-Host "Successfully deleted all existing entities in Azure storage table '$TableName' for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'" + +$configFile = Get-Content -Path $ConfigurationFile | ConvertFrom-Json +foreach ($entityToAdd in $configFile) { + if ($entityToAdd.PartitionKey) { + $partitionKey = $entityToAdd.PartitionKey + $entityToAdd.PSObject.Properties.Remove('PartitionKey') + } else { + $partitionKey = New-Guid + } + + if ($entityToAdd.RowKey) { + $rowKey = $entityToAdd.RowKey + $entityToAdd.PSObject.Properties.Remove('RowKey') + } else { + $rowKey = New-Guid + } + + $entityHash = @{} + $entityToAdd.PSObject.Properties | foreach { $entityHash[$_.Name] = $_.Value } + + $addedRow = Add-AzTableRow ` + -table $cloudTable ` + -partitionKey $partitionKey ` + -rowKey $rowKey ` + -property $entityHash + + Write-Verbose "Successfully added row with PartitionKey '$partitionKey' and RowKey '$rowKey' to Azure storage table '$TableName' for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'" +} + +Write-Host "Successfully added all entities in Azure storage table '$TableName' for Azure storage account '$StorageAccountName' in resource group '$ResourceGroupName'" \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Storage.Table.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Storage.Table.tests.ps1 index d608cf52..804d0bec 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Storage.Table.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Storage.Table.tests.ps1 @@ -87,5 +87,57 @@ InModuleScope Arcus.Scripting.Storage.Table { } } } + Context "Setting Azure Table Storage Entities" { + It "Setting entities in an Azure Table Storage account" { + # Arrange + $resourceGroup = $config.Arcus.ResourceGroupName + $storageAccountName = $config.Arcus.Storage.StorageAccount.Name + $tableName = "SetEntityTable" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config.json" + $storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName + + try { + # Act + Create-AzStorageTable ` + -ResourceGroupName $config.Arcus.ResourceGroupName ` + -StorageAccountName $config.Arcus.Storage.StorageAccount.Name ` + -Table $tableName + + Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile + + # Assert + $storageTable = Get-AzStorageTable –Name $tableName –Context $storageAccount.Context + (Get-AzTableRow -table $storageTable.CloudTable | measure).Count | + Should -Be 2 + } finally { + Remove-AzStorageTable -Name $tableName -Context $storageAccount.Context -Force -ErrorAction SilentlyContinue + } + } + It "Setting entities in an Azure Table Storage account without specifying PartitionKey and RowKey" { + # Arrange + $resourceGroup = $config.Arcus.ResourceGroupName + $storageAccountName = $config.Arcus.Storage.StorageAccount.Name + $tableName = "SetEntityTableNoKeys" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config-nokeys.json" + $storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName + + try { + # Act + Create-AzStorageTable ` + -ResourceGroupName $config.Arcus.ResourceGroupName ` + -StorageAccountName $config.Arcus.Storage.StorageAccount.Name ` + -Table $tableName + + Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile + + # Assert + $storageTable = Get-AzStorageTable –Name $tableName –Context $storageAccount.Context + (Get-AzTableRow -table $storageTable.CloudTable | measure).Count | + Should -Be 2 + } finally { + Remove-AzStorageTable -Name $tableName -Context $storageAccount.Context -Force -ErrorAction SilentlyContinue + } + } + } } } diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj index 136606e6..28b8f81a 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj @@ -61,6 +61,7 @@ + @@ -94,6 +95,8 @@ + + diff --git a/src/Arcus.Scripting.Tests.Integration/Files/TableStorage/set-aztablestorageentities-config-nokeys.json b/src/Arcus.Scripting.Tests.Integration/Files/TableStorage/set-aztablestorageentities-config-nokeys.json new file mode 100644 index 00000000..bcd66dca --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/Files/TableStorage/set-aztablestorageentities-config-nokeys.json @@ -0,0 +1,11 @@ +[ + { + "ReadPath": "/home/in", + "ReadIntervalInSeconds": "30" + }, + { + "ReadPath": "/data/in", + "ReadIntervalInSeconds": "10", + "HasSubdirectories": "true" + } +] \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/Files/TableStorage/set-aztablestorageentities-config.json b/src/Arcus.Scripting.Tests.Integration/Files/TableStorage/set-aztablestorageentities-config.json new file mode 100644 index 00000000..b02caec9 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/Files/TableStorage/set-aztablestorageentities-config.json @@ -0,0 +1,15 @@ +[ + { + "PartitionKey": "SystemA", + "RowKey": "100", + "ReadPath": "/home/in", + "ReadIntervalInSeconds": "30" + }, + { + "PartitionKey": "SystemA", + "RowKey": "200", + "ReadPath": "/data/in", + "ReadIntervalInSeconds": "10", + "HasSubdirectories": "true" + } +] \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Storage.Table.tests.ps1 b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Storage.Table.tests.ps1 index c00cfeed..4a5df2cd 100644 --- a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Storage.Table.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Storage.Table.tests.ps1 @@ -138,5 +138,151 @@ InModuleScope Arcus.Scripting.Storage.Table { Should -Throw } } + Context "Setting Azure Table Storage Entities" { + It "Setting entities in an Azure Table Storage account should succeed" { + # Arrange + $resourceGroup = "SomeResourceGroup" + $storageAccountName = "SomeStorageAccountName" + $tableName = "SomeTableName" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config.json" + $storageAccount = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccount + $psStorageAccount = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount -ArgumentList $storageAccount + + Mock Get-AzStorageAccount { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $storageAccountName + return $psStorageAccount } -Verifiable + Mock Get-AzStorageTable { + $Context | Should -Be $psStorageAccount.Context + return @{ + CloudTable = "123456" + } + } -Verifiable + Mock Get-AzTableRow {} + Mock Remove-AzTableRow {} + Mock Add-AzTableRow {} + + # Act + Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzStorageAccount -Times 1 + Assert-MockCalled Get-AzStorageTable -Times 1 + Assert-MockCalled Get-AzTableRow -Times 1 + Assert-MockCalled Remove-AzTableRow -Times 0 + Assert-MockCalled Add-AzTableRow -Times 2 + } + It "Setting entities in an Azure Table Storage account without PartitionKey and RowKey should succeed" { + # Arrange + $resourceGroup = "SomeResourceGroup" + $storageAccountName = "SomeStorageAccountName" + $tableName = "SomeTableName" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config-nokeys.json" + $storageAccount = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccount + $psStorageAccount = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount -ArgumentList $storageAccount + + Mock Get-AzStorageAccount { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $storageAccountName + return $psStorageAccount } -Verifiable + Mock Get-AzStorageTable { + $Context | Should -Be $psStorageAccount.Context + return @{ + CloudTable = "123456" + } + } -Verifiable + Mock Get-AzTableRow {} + Mock Remove-AzTableRow {} + Mock Add-AzTableRow {} + + # Act + Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzStorageAccount -Times 1 + Assert-MockCalled Get-AzStorageTable -Times 1 + Assert-MockCalled Get-AzTableRow -Times 1 + Assert-MockCalled Remove-AzTableRow -Times 0 + Assert-MockCalled Add-AzTableRow -Times 2 + } + It "Setting entities in an Azure Table Storage account with a storage account that does not exist fails" { + # Arrange + $resourceGroup = "SomeResourceGroup" + $storageAccountName = "SomeStorageAccountName" + $tableName = "SomeTableName" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config.json" + $storageAccount = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccount + $psStorageAccount = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount -ArgumentList $storageAccount + + Mock Get-AzStorageAccount { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $storageAccountName + return $null } -Verifiable + + # Act + { Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile } | + Should -Throw -ExpectedMessage "Retrieving Azure storage account context for Azure storage account '$storageAccountName' in resource group '$resourceGroup' failed." + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzStorageAccount -Times 1 + } + It "Setting entities in an Azure Table Storage account with a storage table that does not exist fails" { + # Arrange + $resourceGroup = "SomeResourceGroup" + $storageAccountName = "SomeStorageAccountName" + $tableName = "SomeTableName" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config.json" + $storageAccount = New-Object -TypeName Microsoft.Azure.Management.Storage.Models.StorageAccount + $psStorageAccount = New-Object -TypeName Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount -ArgumentList $storageAccount + + Mock Get-AzStorageAccount { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $storageAccountName + return $psStorageAccount } -Verifiable + Mock Get-AzStorageTable { + $Context | Should -Be $psStorageAccount.Context + return $null + } -Verifiable + + # Act + { Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile } | + Should -Throw -ExpectedMessage "Retrieving Azure storage table '$tableName' for Azure storage account '$storageAccountName' in resource group '$resourceGroup' failed." + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzStorageAccount -Times 1 + Assert-MockCalled Get-AzStorageTable -Times 1 + } + It "Setting entities in an Azure Table Storage account with a config file that does not exist fails" { + $resourceGroup = "SomeResourceGroup" + $storageAccountName = "SomeStorageAccountName" + $tableName = "SomeTableName" + $configFile = ".\SomeFileThatDoesNotExist.json" + + { Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile } | + Should -Throw -ExpectedMessage "Cannot re-create entities based on JSON configuration file because no file was found at: '$configFile'" + } + It "Setting entities in an Azure Table Storage account with a config file that is empty fails" { + $resourceGroup = "SomeResourceGroup" + $storageAccountName = "SomeStorageAccountName" + $tableName = "SomeTableName" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config-empty.json" + + { Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile } | + Should -Throw -ExpectedMessage "Cannot re-create entities based on JSON configuration file because the file is empty." + } + It "Setting entities in an Azure Table Storage account with a config file that is not valid JSON fails" { + $resourceGroup = "SomeResourceGroup" + $storageAccountName = "SomeStorageAccountName" + $tableName = "SomeTableName" + $configFile = "$PSScriptRoot\Files\TableStorage\set-aztablestorageentities-config-invalid.json" + + { Set-AzTableStorageEntities -ResourceGroupName $resourceGroup -StorageAccountName $storageAccountName -TableName $tableName -ConfigurationFile $configFile } | + Should -Throw -ExpectedMessage "Cannot re-create entities based on JSON configuration file because the file does not contain a valid JSON configuration file." + } + } } } diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj index 73e7621c..a07ecaca 100644 --- a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.Tests.Unit.pssproj @@ -90,6 +90,10 @@ + + + + @@ -103,6 +107,7 @@ + diff --git a/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-empty.json b/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-empty.json new file mode 100644 index 00000000..e69de29b diff --git a/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-invalid.json b/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-invalid.json new file mode 100644 index 00000000..7e31dc3c --- /dev/null +++ b/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-invalid.json @@ -0,0 +1 @@ +this is not JSON \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-nokeys.json b/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-nokeys.json new file mode 100644 index 00000000..bcd66dca --- /dev/null +++ b/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config-nokeys.json @@ -0,0 +1,11 @@ +[ + { + "ReadPath": "/home/in", + "ReadIntervalInSeconds": "30" + }, + { + "ReadPath": "/data/in", + "ReadIntervalInSeconds": "10", + "HasSubdirectories": "true" + } +] \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config.json b/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config.json new file mode 100644 index 00000000..b02caec9 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Unit/Files/TableStorage/set-aztablestorageentities-config.json @@ -0,0 +1,15 @@ +[ + { + "PartitionKey": "SystemA", + "RowKey": "100", + "ReadPath": "/home/in", + "ReadIntervalInSeconds": "30" + }, + { + "PartitionKey": "SystemA", + "RowKey": "200", + "ReadPath": "/data/in", + "ReadIntervalInSeconds": "10", + "HasSubdirectories": "true" + } +] \ No newline at end of file