Skip to content

Commit

Permalink
Improve Unit Test Reliability of Collections in MacOS and Linux - Fixes
Browse files Browse the repository at this point in the history
#176 (#185)

* Modified Unit Tests to Hopefully work reliably in MacOS and Linux

* Rework Collection Unit Test Parameter Filters
  • Loading branch information
PlagueHO committed Oct 14, 2018
1 parent 7047aec commit 69519b2
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 212 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Improved unit test reliability on MacOS and Linux.

## 2.1.8.59

- Fixed RU display - fixes [Issue #168](https://github.com/PlagueHO/CosmosDB/issues/168)
- Fixed Powershell Core `Invoke-WebRequest` error handling.
- Fixed retry logic bug (`$fatal` initially set to `$true` instead of `$false`).
Expand Down
2 changes: 1 addition & 1 deletion RELEASENOTES.md
@@ -1,6 +1,6 @@
# Release Notes

## What is New in CosmosDB Unreleased
## What is New in CosmosDB 2.1.8.59

October 3, 2018

Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDB.psd1
Expand Up @@ -181,7 +181,7 @@

# ReleaseNotes of this module
ReleaseNotes = '
## What is New in CosmosDB Unreleased
## What is New in CosmosDB 2.1.8.59
October 3, 2018
Expand Down
24 changes: 0 additions & 24 deletions test/CosmosDB.accounts.Tests.ps1
Expand Up @@ -91,7 +91,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-AzureRmResource `
-ParameterFilter $getAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -150,7 +149,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName New-AzureRmResource `
-ParameterFilter $newAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -205,7 +203,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName New-AzureRmResource `
-ParameterFilter $newAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -264,7 +261,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName New-AzureRmResource `
-ParameterFilter $newAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -327,7 +323,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName New-AzureRmResource `
-ParameterFilter $newAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -382,7 +377,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName New-AzureRmResource `
-ParameterFilter $newAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -437,7 +431,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName New-AzureRmResource `
-ParameterFilter $newAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -499,7 +492,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand Down Expand Up @@ -565,7 +557,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand All @@ -576,7 +567,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-CosmosDbAccount `
-ParameterFilter $getCosmosDbAccount_parameterFilter `
-MockWith { $script:mockGetAzureRmResource } `
-Verifiable

Expand Down Expand Up @@ -635,7 +625,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand All @@ -646,7 +635,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-CosmosDbAccount `
-ParameterFilter $getCosmosDbAccount_parameterFilter `
-MockWith { $script:mockGetAzureRmResource } `
-Verifiable

Expand Down Expand Up @@ -709,7 +697,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand All @@ -720,7 +707,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-CosmosDbAccount `
-ParameterFilter $getCosmosDbAccount_parameterFilter `
-MockWith { $script:mockGetAzureRmResource } `
-Verifiable

Expand Down Expand Up @@ -775,7 +761,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand All @@ -786,7 +771,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-CosmosDbAccount `
-ParameterFilter $getCosmosDbAccount_parameterFilter `
-MockWith { $script:mockGetAzureRmResource } `
-Verifiable

Expand Down Expand Up @@ -840,7 +824,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand All @@ -851,7 +834,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-CosmosDbAccount `
-ParameterFilter $getCosmosDbAccount_parameterFilter `
-MockWith { $script:mockGetAzureRmResource } `
-Verifiable

Expand Down Expand Up @@ -898,7 +880,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand All @@ -909,7 +890,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-CosmosDbAccount `
-ParameterFilter $getCosmosDbAccount_parameterFilter `
-MockWith { $script:mockGetAzureRmResource } `
-Verifiable

Expand Down Expand Up @@ -964,7 +944,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Set-AzureRmResource `
-ParameterFilter $setAzurRmResource_parameterFilter `
-MockWith { 'Account' } `
-Verifiable

Expand All @@ -975,7 +954,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Get-CosmosDbAccount `
-ParameterFilter $getCosmosDbAccount_parameterFilter `
-MockWith { $script:mockGetAzureRmResource } `
-Verifiable

Expand Down Expand Up @@ -1011,7 +989,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Remove-AzureRmResource `
-ParameterFilter $removeAzurRmResource_parameterFilter `
-Verifiable

It 'Should not throw exception' {
Expand Down Expand Up @@ -1044,7 +1021,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Remove-AzureRmResource `
-ParameterFilter $removeAzurRmResource_parameterFilter `
-Verifiable

It 'Should not throw exception' {
Expand Down
29 changes: 19 additions & 10 deletions test/CosmosDB.attachments.Tests.ps1
Expand Up @@ -107,7 +107,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Get' -and $ResourceType -eq 'Attachments' } `
-MockWith { $script:testGetAttachmentResultMulti }

It 'Should not throw exception' {
Expand All @@ -129,7 +128,10 @@ InModuleScope CosmosDB {
It 'Should call expected mocks' {
Assert-MockCalled `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Get' -and $ResourceType -eq 'Attachments' } `
-ParameterFilter {
$Method -eq 'Get' -and `
$ResourceType -eq 'Attachments'
} `
-Exactly -Times 1
}
}
Expand All @@ -139,7 +141,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Get' -and $ResourceType -eq 'Attachments' -and $ResourcePath -eq ('colls/{0}/docs/{1}/attachments/{2}' -f $script:testCollection, $script:testDocument, $script:testAttachment1) } `
-MockWith { $script:testGetAttachmentResultSingle }

It 'Should not throw exception' {
Expand All @@ -160,7 +161,11 @@ InModuleScope CosmosDB {
It 'Should call expected mocks' {
Assert-MockCalled `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Get' -and $ResourceType -eq 'Attachments' -and $ResourcePath -eq ('colls/{0}/docs/{1}/attachments/{2}' -f $script:testCollection, $script:testDocument, $script:testAttachment1) } `
-ParameterFilter {
$Method -eq 'Get' -and `
$ResourceType -eq 'Attachments' -and `
$ResourcePath -eq ('colls/{0}/docs/{1}/attachments/{2}' -f $script:testCollection, $script:testDocument, $script:testAttachment1)
} `
-Exactly -Times 1
}
}
Expand All @@ -176,7 +181,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Post' -and $ResourceType -eq 'Attachments' } `
-MockWith { $script:testGetAttachmentResultSingle }

It 'Should not throw exception' {
Expand All @@ -199,7 +203,10 @@ InModuleScope CosmosDB {
It 'Should call expected mocks' {
Assert-MockCalled `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Post' -and $ResourceType -eq 'Attachments' } `
-ParameterFilter {
$Method -eq 'Post' -and `
$ResourceType -eq 'Attachments'
} `
-Exactly -Times 1
}
}
Expand All @@ -214,8 +221,7 @@ InModuleScope CosmosDB {
$script:result = $null

Mock `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Delete' -and $ResourceType -eq 'Attachments' -and $ResourcePath -eq ('colls/{0}/docs/{1}/attachments/{2}' -f $script:testCollection, $script:testDocument, $script:testAttachment1) }
-CommandName Invoke-CosmosDbRequest

It 'Should not throw exception' {
$removeCosmosDbAttachmentParameters = @{
Expand All @@ -231,7 +237,11 @@ InModuleScope CosmosDB {
It 'Should call expected mocks' {
Assert-MockCalled `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Delete' -and $ResourceType -eq 'Attachments' -and $ResourcePath -eq ('colls/{0}/docs/{1}/attachments/{2}' -f $script:testCollection, $script:testDocument, $script:testAttachment1) } `
-ParameterFilter {
$Method -eq 'Delete' -and `
$ResourceType -eq 'Attachments' -and `
$ResourcePath -eq ('colls/{0}/docs/{1}/attachments/{2}' -f $script:testCollection, $script:testDocument, $script:testAttachment1)
} `
-Exactly -Times 1
}
}
Expand All @@ -247,7 +257,6 @@ InModuleScope CosmosDB {

Mock `
-CommandName Invoke-CosmosDbRequest `
-ParameterFilter { $Method -eq 'Put' -and $ResourceType -eq 'attachments' } `
-MockWith { $script:testGetAttachmentResultSingle }

It 'Should not throw exception' {
Expand Down

0 comments on commit 69519b2

Please sign in to comment.