Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Integration Tests for Document Query #358

Merged
merged 9 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change Azure DevOps Pipeline definition to include `source/*` - Fixes [Issue #350](https://github.com/PlagueHO/CosmosDB/issues/350).
- Updated pipeline to use `latest` version of `ModuleBuilder` - Fixes [Issue #350](https://github.com/PlagueHO/CosmosDB/issues/350).
- Merge `HISTORIC_CHANGELOG.md` into `CHANGELOG.md` - Fixes [Issue #351](https://github.com/PlagueHO/CosmosDB/issues/351).
- Updated `azure-pipelines.yml` to change Deploy stage to use
a native Azure DevOps `deployment`.
- Added integration tests for executing document queries - Fixes [Issue #356](https://github.com/PlagueHO/CosmosDB/issues/356).

## [3.7.0] - 2020-03-24

Expand Down
67 changes: 35 additions & 32 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ trigger:
- "v*"
exclude:
- "*-*"
pr: none

stages:
- stage: Build
Expand Down Expand Up @@ -567,37 +566,41 @@ stages:
endsWith(variables['Build.DefinitionName'],'master')
)
jobs:
- job: Deploy_Module
- deployment: Deploy_Module
displayName: 'Deploy Module'
pool:
vmImage: ubuntu-16.04

steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'

- task: PowerShell@2
name: publish_release
displayName: 'Publish Release'
inputs:
filePath: './build.ps1'
arguments: '-tasks publish'
pwsh: true
env:
GitHubToken: $(GitHubToken)
GalleryApiToken: $(GalleryApiToken)

- task: PowerShell@2
name: send_changelog_PR
displayName: 'Send CHANGELOG PR'
inputs:
filePath: './build.ps1'
arguments: '-tasks Create_ChangeLog_GitHub_PR'
pwsh: true
env:
GitHubToken: $(GitHubToken)
environment: 'PowerShell Gallery'

strategy:
runOnce:
deploy:
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'

- task: PowerShell@2
name: publish_release
displayName: 'Publish Release'
inputs:
filePath: './build.ps1'
arguments: '-tasks publish'
pwsh: true
env:
GitHubToken: $(GitHubToken)
GalleryApiToken: $(GalleryApiToken)

- task: PowerShell@2
name: send_changelog_PR
displayName: 'Send CHANGELOG PR'
inputs:
filePath: './build.ps1'
arguments: '-tasks Create_ChangeLog_GitHub_PR'
pwsh: true
env:
GitHubToken: $(GitHubToken)
8 changes: 4 additions & 4 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ VersionedOutputDirectory: true
BuildWorkflow:
Compile_Classes: |
{
$classesPath = Join-Path -Path $SourcePath -ChildPath 'classes/CosmosDB'
$classesPath = Join-Path -Path $BuildRoot -ChildPath 'source/classes/CosmosDB'
$classesProjectPath = Join-Path -Path $classesPath -ChildPath 'CosmosDB.csproj'
& dotnet @('build',$classesProjectPath,'/p:Configuration=Release')
$compiledDllPath = Join-Path -Path $classesPath -ChildPath 'bin/Release/netstandard2.0/CosmosDB.dll'
Expand All @@ -29,7 +29,7 @@ BuildWorkflow:
$ModuleVersion = '0.0.1'
}

$destinationPath = $BuildModuleOutput | Join-Path -ChildPath $ProjectName | Join-Path -ChildPath ($ModuleVersion -Split '-')[0]
$destinationPath = $BuildModuleOutput | Join-Path -ChildPath 'CosmosDB' | Join-Path -ChildPath ($ModuleVersion -Split '-')[0]
$null = Copy-Item -Path $compiledDllPath -Destination $destinationPath
}

Expand All @@ -45,8 +45,8 @@ BuildWorkflow:
$ModuleVersion = '0.0.1'
}

$outputPath = "$BuildModuleOutput\$ProjectName\$(($ModuleVersion -Split '-')[0])"
$execute = "New-ExternalHelp -Path '$ProjectPath\docs' -OutputPath '$OutputPath' -Force"
$outputPath = "$BuildModuleOutput\CosmosDB\$(($ModuleVersion -Split '-')[0])"
$execute = "New-ExternalHelp -Path '$BuildRoot\docs' -OutputPath '$OutputPath' -Force"

if ($IsCoreCLR)
{
Expand Down
55 changes: 55 additions & 0 deletions tests/Integration/CosmosDB.integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,61 @@ Describe 'Cosmos DB Module' -Tag 'Integration' {
}
}

Context 'When getting all newly created UTF-8 documents from a collection by using a query' {
It 'Should not throw an exception' {
$script:result = Get-CosmosDbDocument `
-Context $script:testContext `
-CollectionId $script:testCollection `
-Query "SELECT * FROM docs c" `
-Verbose
}

It 'Should return expected object' {
Test-GenericResult -GenericResult $script:result
$script:result.Attachments | Should -BeOfType [System.String]
$script:result.Id | Should -Be $script:testDocumentUTF8Id
$script:result.Content | Should -Be $script:testDocumentUTF8Content
}
}

Context 'When getting newly created UTF-8 document from a collection by using a query' {
It 'Should not throw an exception' {
$script:result = Get-CosmosDbDocument `
-Context $script:testContext `
-CollectionId $script:testCollection `
-Query "SELECT * FROM docs c WHERE (c.id = '$testDocumentUTF8Id')" `
-Verbose
}

It 'Should return expected object' {
Test-GenericResult -GenericResult $script:result
$script:result.Attachments | Should -BeOfType [System.String]
$script:result.Id | Should -Be $script:testDocumentUTF8Id
$script:result.Content | Should -Be $script:testDocumentUTF8Content
}
}

Context 'When getting newly created UTF-8 document from a collection by using a query with parameters' {
It 'Should not throw an exception' {
$script:result = Get-CosmosDbDocument `
-Context $script:testContext `
-CollectionId $script:testCollection `
-Query 'SELECT * FROM docs c WHERE (c.id = @id)' `
-QueryParameters @{
name = '@id'
value = $testDocumentUTF8Id
} `
-Verbose
}

It 'Should return expected object' {
Test-GenericResult -GenericResult $script:result
$script:result.Attachments | Should -BeOfType [System.String]
$script:result.Id | Should -Be $script:testDocumentUTF8Id
$script:result.Content | Should -Be $script:testDocumentUTF8Content
}
}

Context 'When getting newly created UTF-8 document from a collection by using the Id' {
It 'Should not throw an exception' {
$script:result = Get-CosmosDbDocument `
Expand Down
139 changes: 74 additions & 65 deletions tests/Unit/CosmosDB.generic.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,88 +14,97 @@ $modulePath = (Get-Module -Name $ProjectName).Path
$moduleManifestPath = Join-Path -Path ((Get-Module -Name $ProjectName).ModuleBase) -ChildPath "$ProjectName.psd1"
$scriptAnalyzerSettingsPath = "$ProjectPath\PSScriptAnalyzerSettings.psd1"

Context 'PSScriptAnalyzer' {
Import-Module -Name 'PSScriptAnalyzer'

# Perform PSScriptAnalyzer scan
$PSScriptAnalyzerResult = Invoke-ScriptAnalyzer `
-Path $moduleManifestPath `
-Settings $scriptAnalyzerSettingsPath `
-ErrorAction SilentlyContinue `
-Verbose:$false
$PSScriptAnalyzerResult += Invoke-ScriptAnalyzer `
-Path $modulePath `
-Recurse `
-Settings $scriptAnalyzerSettingsPath `
-ErrorAction SilentlyContinue `
-Verbose:$false

$PSScriptAnalyzerErrors = $PSScriptAnalyzerResult | Where-Object {
$_.Severity -eq 'Error'
Describe 'CosmosDB Module' {
if ($PSVersionTable.PSVersion.Major -eq 6 -and $PSVersionTable.PSVersion -lt [System.Version] '6.2.4')
{
Write-Warning -Message ('Minimum supported version of PSScriptAnalyzer for PowerShell Core is 6.2.4 but current version is "{0}".' -f $PSVersionTable.PSVersion)
}

It 'Should have no Error level PowerShell Script Analyzer violations' {
if ($PSScriptAnalyzerErrors -ne $null)
{
Write-Warning -Message 'There are Error level PowerShell Script Analyzer violations that must be fixed:'

foreach ($violation in $PSScriptAnalyzerErrors)
{
Write-Warning -Message "$($violation.Scriptname) (Line $($violation.Line)): $($violation.Message)"
else
{
Context 'PowerShell Script Analyzer' {
Import-Module -Name PSScriptAnalyzer

# Perform PSScriptAnalyzer scan
$PSScriptAnalyzerResult = Invoke-ScriptAnalyzer `
-Path $moduleManifestPath `
-Settings $scriptAnalyzerSettingsPath `
-ErrorAction SilentlyContinue `
-Verbose:$false
$PSScriptAnalyzerResult += Invoke-ScriptAnalyzer `
-Path $modulePath `
-Recurse `
-Settings $scriptAnalyzerSettingsPath `
-ErrorAction SilentlyContinue `
-Verbose:$false

$PSScriptAnalyzerErrors = $PSScriptAnalyzerResult | Where-Object {
$_.Severity -eq 'Error'
}

Write-Warning -Message 'For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/psscriptAnalyzer/'
It 'Should have no Error level PowerShell Script Analyzer violations' {
if ($PSScriptAnalyzerErrors -ne $null)
{
Write-Warning -Message 'There are Error level PowerShell Script Analyzer violations that must be fixed:'

$PSScriptAnalyzerErrors.Count | Should -BeNullOrEmpty
}
}
foreach ($violation in $PSScriptAnalyzerErrors)
{
Write-Warning -Message "$($violation.Scriptname) (Line $($violation.Line)): $($violation.Message)"
}

It 'Should have no Warning level PowerShell Script Analyzer violations' {
$PSScriptAnalyzerWarnings = $PSScriptAnalyzerResult | Where-Object {
$_.Severity -eq 'Warning'
}
Write-Warning -Message 'For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/psscriptAnalyzer/'

if ($PSScriptAnalyzerWarnings -ne $null)
{
Write-Warning -Message 'There are Warning level PowerShell Script Analyzer violations that should be fixed:'

foreach ($violation in $PSScriptAnalyzerWarnings)
{
Write-Warning -Message "$($violation.Scriptname) (Line $($violation.Line)): $($violation.Message)"
$PSScriptAnalyzerErrors.Count | Should -BeNullOrEmpty
}
}

Write-Warning -Message 'For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/psscriptAnalyzer/'
}
}
It 'Should have no Warning level PowerShell Script Analyzer violations' {
$PSScriptAnalyzerWarnings = $PSScriptAnalyzerResult | Where-Object {
$_.Severity -eq 'Warning'
}

It 'Should have no Information level PowerShell Script Analyzer violations' {
$PSScriptAnalyzerInformation = $PSScriptAnalyzerResult | Where-Object {
$_.Severity -eq 'Information'
}
if ($PSScriptAnalyzerWarnings -ne $null)
{
Write-Warning -Message 'There are Warning level PowerShell Script Analyzer violations that should be fixed:'

if ($PSScriptAnalyzerInformation -ne $null)
{
Write-Warning -Message 'There are Information level PowerShell Script Analyzer violations that must be fixed:'
foreach ($violation in $PSScriptAnalyzerWarnings)
{
Write-Warning -Message "$($violation.Scriptname) (Line $($violation.Line)): $($violation.Message)"
}

foreach ($violation in $PSScriptAnalyzerInformation)
{
Write-Warning -Message "$($violation.Scriptname) (Line $($violation.Line)): $($violation.Message)"
Write-Warning -Message 'For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/psscriptAnalyzer/'
}
}

Write-Warning -Message 'For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/psscriptAnalyzer/'
It 'Should have no Information level PowerShell Script Analyzer violations' {
$PSScriptAnalyzerInformation = $PSScriptAnalyzerResult | Where-Object {
$_.Severity -eq 'Information'
}

$PSScriptAnalyzerErrors.Count | Should -Be $null
if ($PSScriptAnalyzerInformation -ne $null)
{
Write-Warning -Message 'There are Information level PowerShell Script Analyzer violations that must be fixed:'

foreach ($violation in $PSScriptAnalyzerInformation)
{
Write-Warning -Message "$($violation.Scriptname) (Line $($violation.Line)): $($violation.Message)"
}

Write-Warning -Message 'For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/psscriptAnalyzer/'

$PSScriptAnalyzerErrors.Count | Should -Be $null
}
}
}
}
}

Context 'Manifest' {
It 'Should have a valid manifest' {
$script:moduleManifest = Test-ModuleManifest -Path $moduleManifestPath
$script:moduleManifest | Should -Not -BeNullOrEmpty
}
Context 'Module Manifest' {
It 'Should have a valid manifest' {
$script:moduleManifest = Test-ModuleManifest -Path $moduleManifestPath
$script:moduleManifest | Should -Not -BeNullOrEmpty
}

It 'Should have less than 10000 characters in the release notes of the module manifest' {
$script:moduleManifest.ReleaseNotes.Length | Should -BeLessThan 10000
It 'Should have less than 10000 characters in the release notes of the module manifest' {
$script:moduleManifest.ReleaseNotes.Length | Should -BeLessThan 10000
}
}
}