From 5108885dc5397e4d468c1f8555683d93039f07f3 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Sat, 20 Oct 2018 15:52:26 +0200 Subject: [PATCH] Fixed tests --- JiraPS.build.ps1 | 7 ++- .../Invoke-JiraMethod.Unit.Tests.ps1 | 43 ++++++++++--------- Tests/Project.Tests.ps1 | 7 ++- azure-pipelines.yml | 8 ++-- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/JiraPS.build.ps1 b/JiraPS.build.ps1 index 872e99cf..3dd687f1 100644 --- a/JiraPS.build.ps1 +++ b/JiraPS.build.ps1 @@ -162,7 +162,7 @@ task PrepareTests Init, { # Synopsis: Compile all functions into the .psm1 file task CompileModule Init, { - $regionsToKeep = @('Dependencies', 'ModuleConfig') + $regionsToKeep = @('Dependencies', 'Configuration') $targetFile = "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psm1" $content = Get-Content -Encoding UTF8 -LiteralPath $targetFile @@ -225,7 +225,9 @@ task UpdateManifest GetNextVersion, { } # Synopsis: Create a ZIP file with this build -task Package GenerateRelease, { +task Package Init, { + Assert-True { Test-Path "$env:BHBuildOutput\$env:BHProjectName" } "Missing files to package" + Remove-Item "$env:BHBuildOutput\$env:BHProjectName.zip" -ErrorAction SilentlyContinue $null = Compress-Archive -Path "$env:BHBuildOutput\$env:BHProjectName" -DestinationPath "$env:BHBuildOutput\$env:BHProjectName.zip" } @@ -246,6 +248,7 @@ task Test Init, { $codeCoverageFiles = Get-ChildItem @params #> try { + $ExcludeTag | Out-String | Write-Host $parameter = @{ Script = "$env:BHBuildOutput/Tests/*" Tag = $Tag diff --git a/Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1 b/Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1 index 0f22865a..45f67dd6 100644 --- a/Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1 +++ b/Tests/Functions/Invoke-JiraMethod.Unit.Tests.ps1 @@ -95,12 +95,13 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' { Mock Invoke-WebRequest -ModuleName $env:BHProjectName { ShowMockInfo 'Invoke-WebRequest' -Params 'Uri', 'Method', 'Body', 'Headers', 'ContentType', 'SessionVariable', 'WebSession' $InvokeWebRequestSplat = @{ - Uri = $Uri - Method = $Method - Body = $Body - Headers = $Headers - WebSession = $WebSession - ContentType = $ContentType + Uri = $Uri + Method = $Method + Body = $Body + Headers = $Headers + WebSession = $WebSession + ContentType = $ContentType + UseBasicParsing = $true } if ($SessionVariable) { $InvokeWebRequestSplat["SessionVariable"] = $SessionVariable @@ -221,7 +222,7 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' { ParameterFilter = { $Body -is [Byte[]] -and (($Body -join " ") -eq "76 111 114 101 109 32 195 153 226 128 166 195 152 194 177 195 152 194 173 195 152 194 168 195 152 194 167 32 195 144 226 128 148 195 144 194 180 195 145 226 130 172 195 144 194 176 195 144 194 178 195 145 194 129 195 145 226 128 154 195 144 194 178 195 145 198 146 195 144 194 185 195 145 226 128 154 195 144 194 181 32 195 176 197 184 203 156 194 129" -or - ($Body -join " ") -eq "76 111 114 101 109 32 217 133 216 177 216 173 216 168 216 167 32 208 151 208 180 209 128 208 176 208 178 209 129 209 130 208 178 209 131 208 185 209 130 208 181 32 240 159 152 129") + ($Body -join " ") -eq "76 111 114 101 109 32 217 133 216 177 216 173 216 168 216 167 32 208 151 208 180 209 128 208 176 208 178 209 129 209 130 208 178 209 131 208 185 209 130 208 181 32 240 159 152 129") } Exactly = $true Times = 1 @@ -329,12 +330,12 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' { Invoke-JiraMethod -Method get -URI "https://postman-echo.com/get" -OutputType $type -Paging -ErrorAction Stop $assertMockCalledSplat = @{ - CommandName = "Convert-Result" - ModuleName = $env:BHProjectName + CommandName = "Convert-Result" + ModuleName = $env:BHProjectName ParameterFilter = { $OutputType -eq $type} - Exactly = $true - Times = 1 - Scope = 'It' + Exactly = $true + Times = 1 + Scope = 'It' } Assert-MockCalled @assertMockCalledSplat } @@ -343,12 +344,12 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' { Invoke-JiraMethod -Method get -URI "https://postman-echo.com/get" -OutputType $type -ErrorAction Stop $assertMockCalledSplat = @{ - CommandName = "Convert-Result" - ModuleName = $env:BHProjectName + CommandName = "Convert-Result" + ModuleName = $env:BHProjectName ParameterFilter = { $OutputType -eq $type} - Exactly = $true - Times = 0 - Scope = 'It' + Exactly = $true + Times = 0 + Scope = 'It' } Assert-MockCalled @assertMockCalledSplat } @@ -546,9 +547,11 @@ Describe "Invoke-JiraMethod" -Tag 'Unit' { } $InvokeWebRequestSplat = @{ - Uri = "https://postman-echo.com/post" - Method = "Post" - Body = $response + Uri = "https://postman-echo.com/post" + Method = "Post" + Body = $response + UseBasicParsing = $true + } $result = Microsoft.PowerShell.Utility\Invoke-WebRequest @InvokeWebRequestSplat diff --git a/Tests/Project.Tests.ps1 b/Tests/Project.Tests.ps1 index 55f23bfe..076e47ae 100644 --- a/Tests/Project.Tests.ps1 +++ b/Tests/Project.Tests.ps1 @@ -123,10 +123,13 @@ Describe "General project validation" -Tag Unit { } It "has all the public functions as a file in '$env:BHProjectName/Public'" { - $publicFunctions = (Get-Module -Name $env:BHProjectName).ExportedCommands.Keys + $module = (Get-Module -Name $env:BHProjectName) + $publicFunctions = $module.ExportedFunctions.Keys foreach ($function in $publicFunctions) { - # $function = $function.Replace((Get-Module -Name $env:BHProjectName).Prefix, '') + if ($module.Prefix) { + $function = $function.Replace($module.Prefix, '') + } (Get-ChildItem "$env:BHModulePath/Public").BaseName | Should -Contain $function } diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 48f1e913..c1fb18f8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -55,7 +55,7 @@ phases: Invoke-Build -Task ShowInfo displayName: Setup - - powershell: 'Invoke-Build -Task Test -ExcludeTag "Integration"' + - powershell: 'Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration"' displayName: Test - task: PublishTestResults@2 @@ -87,7 +87,7 @@ phases: Invoke-Build -Task ShowInfo displayName: Setup - - powershell: 'Invoke-Build -Task Test -ExcludeTag "Integration"' + - powershell: 'Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration"' displayName: Test - task: PublishTestResults@2 @@ -118,7 +118,7 @@ phases: Invoke-Build -Task ShowInfo displayName: Setup - - powershell: 'Invoke-Build -Task Test -ExcludeTag "Integration"' + - powershell: 'Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration"' displayName: Test - task: PublishTestResults@2 @@ -154,7 +154,7 @@ phases: - powershell: | $Env:Path = [Environment]::GetEnvironmentVariable('Path',[EnvironmentVariableTarget]::Machine) - pwsh -command "Invoke-Build -Task Test -ExcludeTag "Integration"" + pwsh -command "Invoke-Build -Task Test -ExcludeTag "Documentation", "Integration"" displayName: Test - task: PublishTestResults@2