Skip to content

Commit

Permalink
tests for etag validation, closes #63 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmEmanuel authored Mar 21, 2024
2 parents 8ff37e3 + 7543100 commit 7f373cb
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/AzuriteIntegration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ Describe 'Azurite Integration Tests' -Tag 'Integration' {
}
}

It 'cannot update changed entities without -Force' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
$Users1 = Get-AzDataTableEntity -Context $Context
$Users2 = Get-AzDataTableEntity -Context $Context
$Users1 = $Users1 | ForEach-Object {
$_.Value1 = 'Updated'
$_
}
$Users2 = $Users2 | ForEach-Object {
$_.Prop1 = 'Will conflict with update from Result1'
$_
}
Update-AzDataTableEntity -Context $Context -Entity $Users1 | Should -BeNullOrEmpty
{ Update-AzDataTableEntity -Context $Context -Entity $Users2 } | Should -Throw
(Get-AzDataTableEntity -Context $Context -Filter "Value1 eq 'Updated'").Count | Should -Be $Users1.Count
{ Update-AzDataTableEntity -Context $Context -Entity $Users2 -Force } | Should -Not -Throw
(Get-AzDataTableEntity -Context $Context -Filter "Value1 eq 'Updated'").Count | Should -Be 0
}

It 'can get count of entities' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
Get-AzDataTableEntity -Context $Context -Count | Should -BeExactly 4
Expand All @@ -117,6 +136,23 @@ Describe 'Azurite Integration Tests' -Tag 'Integration' {
(Get-AzDataTableEntity -Context $Context).Count | Should -BeExactly ($UsersHashtable.Count - $UsersToRemoveHashtable.Count)
}

It 'cannot remove changed entities without -Force' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
$Users1 = Get-AzDataTableEntity -Context $Context
$Users2 = Get-AzDataTableEntity -Context $Context
$Users1 = $Users1 | ForEach-Object {
$_.Value1 = 'Updated'
$_
}
Update-AzDataTableEntity -Context $Context -Entity $Users1 | Should -BeNullOrEmpty
{ Remove-AzDataTableEntity -Context $Context -Entity $Users2 } | Should -Throw
(Get-AzDataTableEntity -Context $Context -Filter "Value1 eq 'Updated'").Count | Should -Be $Users1.Count
{ Remove-AzDataTableEntity -Context $Context -Entity $Users2 -Force } | Should -Not -Throw
(Get-AzDataTableEntity -Context $Context).Count | Should -Be 0
# Restore table for next test
Add-AzDataTableEntity -Context $Context -Entity $Users2 | Should -BeNullOrEmpty
}

It 'can clear table' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
Get-AzDataTableEntity -Context $Context | Should -Not -BeNullOrEmpty
Expand Down Expand Up @@ -214,6 +250,25 @@ Describe 'Azurite Integration Tests' -Tag 'Integration' {
}
}

It 'cannot update changed entities without -Force' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
$Users1 = Get-AzDataTableEntity -Context $Context
$Users2 = Get-AzDataTableEntity -Context $Context
$Users1 = $Users1 | ForEach-Object {
$_.Value1 = 'Updated'
$_
}
$Users2 = $Users2 | ForEach-Object {
$_.Prop1 = 'Will conflict with update from Result1'
$_
}
Update-AzDataTableEntity -Context $Context -Entity $Users1 | Should -BeNullOrEmpty
{ Update-AzDataTableEntity -Context $Context -Entity $Users2 } | Should -Throw
(Get-AzDataTableEntity -Context $Context -Filter "Value1 eq 'Updated'").Count | Should -Be $Users1.Count
{ Update-AzDataTableEntity -Context $Context -Entity $Users2 -Force } | Should -Not -Throw
(Get-AzDataTableEntity -Context $Context -Filter "Value1 eq 'Updated'").Count | Should -Be 0
}

It 'can get count of entities' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
Get-AzDataTableEntity -Context $Context -Count | Should -BeExactly 4
Expand All @@ -225,6 +280,23 @@ Describe 'Azurite Integration Tests' -Tag 'Integration' {
(Get-AzDataTableEntity -Context $Context).Count | Should -BeExactly ($UsersPSObjects.Count - $UsersToRemovePSObjects.Count)
}

It 'cannot remove changed entities without -Force' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
$Users1 = Get-AzDataTableEntity -Context $Context
$Users2 = Get-AzDataTableEntity -Context $Context
$Users1 = $Users1 | ForEach-Object {
$_.Value1 = 'Updated'
$_
}
Update-AzDataTableEntity -Context $Context -Entity $Users1 | Should -BeNullOrEmpty
{ Remove-AzDataTableEntity -Context $Context -Entity $Users2 } | Should -Throw
(Get-AzDataTableEntity -Context $Context -Filter "Value1 eq 'Updated'").Count | Should -Be $Users1.Count
{ Remove-AzDataTableEntity -Context $Context -Entity $Users2 -Force } | Should -Not -Throw
(Get-AzDataTableEntity -Context $Context).Count | Should -Be 0
# Restore table for next test
Add-AzDataTableEntity -Context $Context -Entity $Users2 | Should -BeNullOrEmpty
}

It 'can clear table' {
$Context = New-AzDataTableContext -TableName $TableName -ConnectionString $ConnectionString
Get-AzDataTableEntity -Context $Context | Should -Not -BeNullOrEmpty
Expand Down

0 comments on commit 7f373cb

Please sign in to comment.