diff --git a/.vscode/settings.json b/.vscode/settings.json index db8c43f..38d4a35 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,6 @@ //-------- Editor configuration -------- "editor.insertSpaces": true, "editor.tabSize": 4, - //-------- Files configuration -------- "files.autoGuessEncoding": false, "files.insertFinalNewline": true, @@ -11,17 +10,15 @@ "search.exclude": { "**/Tests/Data*": true }, - //-------- PowerShell configuration -------- "powershell.codeFormatting.alignPropertyValuePairs": true, "powershell.codeFormatting.preset": "Allman", + "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationAfterEveryPipeline", "powershell.scriptAnalysis.settingsPath": "./ScriptAnalyzerSettings.psd1", - //-------- Language configuration -------- "[json]": { "editor.tabSize": 2 }, - "[xml]": { "editor.tabSize": 2 }, @@ -32,6 +29,14 @@ "titleBar.inactiveForeground": "#e7e7e799", "statusBar.background": "#2ba66c", "statusBarItem.hoverBackground": "#38cc86", - "statusBar.foreground": "#e7e7e7" - } + "statusBar.foreground": "#e7e7e7", + "activityBar.activeBackground": "#38cc86", + "activityBar.activeBorder": "#934dd1", + "activityBar.background": "#38cc86", + "activityBar.foreground": "#15202b", + "activityBar.inactiveForeground": "#15202b99", + "activityBarBadge.background": "#934dd1", + "activityBarBadge.foreground": "#e7e7e7" + }, + "peacock.color": "#2ba66c" } diff --git a/BuildTasks/GenerateMarkdown.Task.ps1 b/BuildTasks/GenerateMarkdown.Task.ps1 index cfb4204..28ffc98 100644 --- a/BuildTasks/GenerateMarkdown.Task.ps1 +++ b/BuildTasks/GenerateMarkdown.Task.ps1 @@ -27,6 +27,7 @@ task GenerateMarkdown { Module = $ModuleName OutputFolder = "$DocsPath\en-US" WithModulePage = $true + Force = $true } # ErrorAction is set to SilentlyContinue so this diff --git a/BuildTasks/ImportDevModule.Task.ps1 b/BuildTasks/ImportDevModule.Task.ps1 index c868aa7..178bf1f 100644 --- a/BuildTasks/ImportDevModule.Task.ps1 +++ b/BuildTasks/ImportDevModule.Task.ps1 @@ -1,4 +1,4 @@ task ImportDevModule { - ImportModule -Path "$Source\$ModuleName.psd1" -Force + Import-BuildModule -Path "$Source\$ModuleName.psd1" -Force } diff --git a/BuildTasks/ImportModule.Task.ps1 b/BuildTasks/ImportModule.Task.ps1 index a903b45..39e0286 100644 --- a/BuildTasks/ImportModule.Task.ps1 +++ b/BuildTasks/ImportModule.Task.ps1 @@ -1,4 +1,4 @@ -function ImportModule +function Import-BuildModule { param( [string]$path, @@ -29,5 +29,5 @@ function ImportModule } task ImportModule { - ImportModule -Path $ManifestPath + Import-BuildModule -Path $ManifestPath } diff --git a/BuildTasks/InvokeBuildInit.ps1 b/BuildTasks/InvokeBuildInit.ps1 index 620e51d..ae1c03d 100644 --- a/BuildTasks/InvokeBuildInit.ps1 +++ b/BuildTasks/InvokeBuildInit.ps1 @@ -22,6 +22,8 @@ Write-Verbose " ModulePath [$ModulePath]" -Verbose $Script:Folders = 'Classes', 'Includes', 'Internal', 'Private', 'Public', 'Resources' Write-Verbose " Folders [$Folders]" -Verbose +$timestamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." } +$PSVersion = $PSVersionTable.PSVersion.ToString() $Script:TestFile = "$BuildRoot\Output\TestResults_PS$PSVersion`_$TimeStamp.xml" Write-Verbose " TestFile [$TestFile]" -Verbose diff --git a/BuildTasks/Pester.Task.ps1 b/BuildTasks/Pester.Task.ps1 index 3a4f2fe..4487ae3 100644 --- a/BuildTasks/Pester.Task.ps1 +++ b/BuildTasks/Pester.Task.ps1 @@ -1,34 +1,34 @@ task Pester { $requiredPercent = $Script:CodeCoveragePercent + Import-Module Pester -Force + $configuration = [PesterConfiguration]::Default + # assing properties & discover via intellisense + $configuration.Run.Path = 'Tests' + $configuration.Filter.Tag = 'Build' + $configuration.Run.PassThru = $true + $configuration.Output.Verbosity = 'Detailed' + $configuration.TestResult.Enabled = $true + $configuration.TestResult.OutputFormat = 'NUnitXml' + $configuration.TestResult.OutputPath = $testFile - $params = @{ - OutputFile = $testFile - OutputFormat = 'NUnitXml' - PassThru = $true - Path = 'Tests' - Show = 'Failed', 'Fails', 'Summary' - Tag = 'Build' - } + if ($requiredPercent -gt 0.00) { - if($requiredPercent -gt 0.00) - { - $params['CodeCoverage'] = 'Output\*\*.psm1' - $params['CodeCoverageOutputFile'] = 'Output\codecoverage.xml' + $configuration.CodeCoverage.Enabled = $true + $configuration.CodeCoverage.OutputPath = 'Output\codecoverage.xml' } - $results = Invoke-Pester @params - if ($results.FailedCount -gt 0) - { - Write-Error -Message "Failed [$($results.FailedCount)] Pester tests." - } + $results = Invoke-Pester -Configuration $configuration + if ($requiredPercent -gt 0.00) { - if($results.codecoverage.NumberOfCommandsAnalyzed -gt 0) - { - $codeCoverage = $results.codecoverage.NumberOfCommandsExecuted / $results.codecoverage.NumberOfCommandsAnalyzed + if ($results.TotalCount -gt 0) { + $CodeCoveragePercent = $results.TotalCount * ($results.PassedCount / 100) + $codeCoverage = [math]::Round($CodeCoveragePercent,2) - if($codeCoverage -lt $requiredPercent) - { - Write-Error ("Failed Code Coverage [{0:P}] below {1:P}" -f $codeCoverage,$requiredPercent) + if ($codeCoverage -lt [Math]::Round($requiredPercent,2)) { + Write-Error ("Failed Code Coverage [{0:P}] below {1:P}" -f $codeCoverage, $requiredPercent) + } } + } elseif ($results.FailedCount -gt 0) { + Write-Error -Message "Failed [$($results.FailedCount)] Pester tests." } } diff --git a/BuildTasks/SetVersion.Task.ps1 b/BuildTasks/SetVersion.Task.ps1 index 1587856..f1df7da 100644 --- a/BuildTasks/SetVersion.Task.ps1 +++ b/BuildTasks/SetVersion.Task.ps1 @@ -1,7 +1,7 @@ function GetModulePublicInterfaceMap { param($Path) - $module = ImportModule -Path $Path -PassThru + $module = Import-BuildModule -Path $Path -PassThru $exportedCommands = @( $module.ExportedFunctions.values $module.ExportedCmdlets.values @@ -50,7 +50,7 @@ task SetVersion { "Checking for published version" $publishedModule = Find-Module -Name $ModuleName -ErrorAction 'Ignore' | Sort-Object -Property {[version]$_.Version} -Descending | - Select -First 1 + Select-Object -First 1 if($null -ne $publishedModule) { diff --git a/Docs/en-US/Add-SnowSqlRoleMember.md b/Docs/en-US/Add-SnowSqlRoleMember.md index c06f625..32405f7 100644 --- a/Docs/en-US/Add-SnowSqlRoleMember.md +++ b/Docs/en-US/Add-SnowSqlRoleMember.md @@ -21,7 +21,7 @@ Add users to role ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Add-SnowSqlRoleMember -Role TEST_ROLE -Name TEST_USER ``` diff --git a/Docs/en-US/Disable-SnowSqlUser.md b/Docs/en-US/Disable-SnowSqlUser.md index 0575604..49e2394 100644 --- a/Docs/en-US/Disable-SnowSqlUser.md +++ b/Docs/en-US/Disable-SnowSqlUser.md @@ -21,7 +21,7 @@ Disable user account ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Disable-SnowSqlUser -Name TEST_USER ``` diff --git a/Docs/en-US/Enable-SnowSqlUser.md b/Docs/en-US/Enable-SnowSqlUser.md index 6ca9346..cd4e71e 100644 --- a/Docs/en-US/Enable-SnowSqlUser.md +++ b/Docs/en-US/Enable-SnowSqlUser.md @@ -21,7 +21,7 @@ Enable user account ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Enable-SnowSqlUser -Name TEST_USER ``` diff --git a/Docs/en-US/Get-SnowSqlConnection.md b/Docs/en-US/Get-SnowSqlConnection.md index 217a847..8d0ebe7 100644 --- a/Docs/en-US/Get-SnowSqlConnection.md +++ b/Docs/en-US/Get-SnowSqlConnection.md @@ -21,7 +21,7 @@ Gets the current Snowflake connection ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Get-SnowSqlConnection ``` diff --git a/Docs/en-US/Get-SnowSqlRole.md b/Docs/en-US/Get-SnowSqlRole.md index ab65f58..5acdaa9 100644 --- a/Docs/en-US/Get-SnowSqlRole.md +++ b/Docs/en-US/Get-SnowSqlRole.md @@ -21,7 +21,7 @@ Get list of Snowflake roles ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Get-SnowSqlRole ``` diff --git a/Docs/en-US/Get-SnowSqlRoleMember.md b/Docs/en-US/Get-SnowSqlRoleMember.md index 8c32411..c475052 100644 --- a/Docs/en-US/Get-SnowSqlRoleMember.md +++ b/Docs/en-US/Get-SnowSqlRoleMember.md @@ -21,7 +21,7 @@ Gets the members of the Snowflake role ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Get-SnowSqlRoleMember ``` diff --git a/Docs/en-US/Get-SnowSqlUser.md b/Docs/en-US/Get-SnowSqlUser.md index 527b7ca..68e876b 100644 --- a/Docs/en-US/Get-SnowSqlUser.md +++ b/Docs/en-US/Get-SnowSqlUser.md @@ -21,7 +21,7 @@ Get list of Snowflake users ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Get-SnowSqlUser ``` diff --git a/Docs/en-US/Invoke-SnowSql.md b/Docs/en-US/Invoke-SnowSql.md index d73a676..6dd1474 100644 --- a/Docs/en-US/Invoke-SnowSql.md +++ b/Docs/en-US/Invoke-SnowSql.md @@ -14,7 +14,8 @@ Invokes a Snowflake SQL statement ### QueryConnection (Default) ``` -Invoke-SnowSql [-Connection ] [-Query ] [-WhatIf] [-Confirm] [] +Invoke-SnowSql [-Connection ] [-Query ] [-Timeout ] [-WhatIf] [-Confirm] + [] ``` ### PathCred @@ -25,8 +26,8 @@ Invoke-SnowSql -Endpoint -Credential [-Path ] [- ### QueryCred ``` -Invoke-SnowSql -Endpoint -Credential [-Query ] [-WhatIf] [-Confirm] - [] +Invoke-SnowSql -Endpoint -Credential [-Query ] [-Timeout ] [-WhatIf] + [-Confirm] [] ``` ### PathConnection @@ -39,7 +40,7 @@ Invokes a Snowflake SQL statement ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Open-SnowSqlConnection ``` @@ -123,6 +124,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Timeout +Login timeout in seconds + +```yaml +Type: Int32 +Parameter Sets: QueryConnection, QueryCred +Aliases: + +Required: False +Position: Named +Default value: 10 +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Confirm Prompts you for confirmation before running the cmdlet. diff --git a/Docs/en-US/New-SnowSqlRole.md b/Docs/en-US/New-SnowSqlRole.md index 33189fc..11b7850 100644 --- a/Docs/en-US/New-SnowSqlRole.md +++ b/Docs/en-US/New-SnowSqlRole.md @@ -21,7 +21,7 @@ Create a new Snowflake role ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` New-SnowSqlRole -Role TEST_ROLE ``` diff --git a/Docs/en-US/New-SnowSqlUser.md b/Docs/en-US/New-SnowSqlUser.md index 187f574..1af668b 100644 --- a/Docs/en-US/New-SnowSqlUser.md +++ b/Docs/en-US/New-SnowSqlUser.md @@ -22,7 +22,7 @@ Create a new Snowflake user account ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` New-SnowSqlUser -Name TESTUSER -LoginName TESTUSER@CONTOSO.COM -Description 'AD Account' ``` diff --git a/Docs/en-US/Open-SnowSqlConnection.md b/Docs/en-US/Open-SnowSqlConnection.md index 4b58612..eba2609 100644 --- a/Docs/en-US/Open-SnowSqlConnection.md +++ b/Docs/en-US/Open-SnowSqlConnection.md @@ -13,8 +13,8 @@ Opens a connection to Snowflake ## SYNTAX ``` -Open-SnowSqlConnection [-Endpoint] [-Credential] [-WhatIf] [-Confirm] - [] +Open-SnowSqlConnection [-Endpoint] [-Credential] [[-Timeout] ] [-WhatIf] + [-Confirm] [] ``` ## DESCRIPTION @@ -22,7 +22,7 @@ Establishes a few important environment values for connecting to snowflake ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Open-SnowSqlConnection -Endpoint contoso.east-us-2.azure -Credential (Get-Credential) ``` @@ -59,6 +59,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Timeout +Login timeout in seconds + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: 10 +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Confirm Prompts you for confirmation before running the cmdlet. @@ -75,7 +90,8 @@ Accept wildcard characters: False ``` ### -WhatIf -Shows what would happen if the cmdlet runs. The cmdlet is not run. +Shows what would happen if the cmdlet runs. +The cmdlet is not run. ```yaml Type: SwitchParameter diff --git a/Docs/en-US/Remove-SnowSqlRoleMember.md b/Docs/en-US/Remove-SnowSqlRoleMember.md index 6b35e2a..8594717 100644 --- a/Docs/en-US/Remove-SnowSqlRoleMember.md +++ b/Docs/en-US/Remove-SnowSqlRoleMember.md @@ -21,7 +21,7 @@ Remove Snowflake user from role ## EXAMPLES -### EXAMPLE 1 +### EXEMPLE 1 ``` Remove-SnowSqlRoleMember -Role TEST_ROLE -Name TEST_USER ``` diff --git a/Module.build.ps1 b/Module.build.ps1 index f549433..6955b50 100644 --- a/Module.build.ps1 +++ b/Module.build.ps1 @@ -10,6 +10,6 @@ task Publish Build, PublishVersion, Helpify, Test, PublishModule task TFS Clean, Build, PublishVersion, Helpify, Test task DevTest ImportDevModule, Pester -Write-Host 'Import common tasks' +Write-Information 'Import common tasks' Get-ChildItem -Path $buildroot\BuildTasks\*.Task.ps1 | - ForEach-Object {Write-Host $_.FullName;. $_.FullName} + ForEach-Object {Write-Information $_.FullName;. $_.FullName} diff --git a/ScriptAnalyzerSettings.psd1 b/ScriptAnalyzerSettings.psd1 index e42e87d..cca85a3 100644 --- a/ScriptAnalyzerSettings.psd1 +++ b/ScriptAnalyzerSettings.psd1 @@ -3,7 +3,7 @@ # subset of: Error, Warning and Information. # Uncomment the following line if you only want Errors and Warnings but # not Information diagnostic records. - Severity = @('Error','Warning') + #Severity = @('Error','Warning') # Use IncludeRules when you want to run only a subset of the default rule set. #IncludeRules = @('PSAvoidDefaultValueSwitchParameter', @@ -18,17 +18,17 @@ # Use ExcludeRules when you want to run most of the default set of rules except # for a few rules you wish to "exclude". Note: if a rule is in both IncludeRules # and ExcludeRules, the rule will be excluded. - ExcludeRules = @('PSUseToExportFieldsInManifest','PSMissingModuleManifestField') + ExcludeRules = @('PSMissingModuleManifestField') # You can use the following entry to supply parameters to rules that take parameters. # For instance, the PSAvoidUsingCmdletAliases rule takes a whitelist for aliases you # want to allow. - Rules = @{ + #Rules = @{ # Do not flag 'cd' alias. - PSAvoidUsingCmdletAliases = @{Whitelist = @('Where','Select')} + # PSAvoidUsingCmdletAliases = @{Whitelist = @('Where','Select')} # Check if your script uses cmdlets that are compatible on PowerShell Core, # version 6.0.0-alpha, on Linux. # PSUseCompatibleCmdlets = @{Compatibility = @("core-6.0.0-alpha-linux")} - } + #} } diff --git a/SnowSQL/SnowSQL.psd1 b/SnowSQL/SnowSQL.psd1 index e7deb16..f50107e 100644 --- a/SnowSQL/SnowSQL.psd1 +++ b/SnowSQL/SnowSQL.psd1 @@ -12,7 +12,7 @@ RootModule = 'SnowSQL.psm1' # Version number of this module. -ModuleVersion = '0.1.1' +ModuleVersion = '0.1.3' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/SnowSQL/SnowSQL.psm1 b/SnowSQL/SnowSQL.psm1 index dcdbde2..e75e205 100644 --- a/SnowSQL/SnowSQL.psm1 +++ b/SnowSQL/SnowSQL.psm1 @@ -29,7 +29,7 @@ foreach($file in $classFiles) } } -$importOrder = $classes.GetEnumerator() | +$importOrder = $classes.GetEnumerator() | Resolve-DependencyOrder -Key {$_.Name} -DependsOn {$_.Value.Base} foreach( $class in $importOrder ) diff --git a/SnowSQL/public/Invoke-SnowSql.ps1 b/SnowSQL/public/Invoke-SnowSql.ps1 index 48a7cb4..bb84058 100644 --- a/SnowSQL/public/Invoke-SnowSql.ps1 +++ b/SnowSQL/public/Invoke-SnowSql.ps1 @@ -44,6 +44,12 @@ function Invoke-SnowSql [string[]] $Query = '!help', + # Login timeout in seconds + [Parameter(ParameterSetName = 'QueryCred')] + [Parameter(ParameterSetName = 'QueryConnection')] + [int] + $Timeout = 10, + # SnowSql script file to execute [Parameter(ParameterSetName = 'PathCred')] [Parameter(ParameterSetName = 'PathConnection')] @@ -63,9 +69,9 @@ function Invoke-SnowSql Write-Error "Could not find [snowsql.exe] on local system. Install snowsql.exe and make it available in the %path%. Install instructions can be found here [https://docs.snowflake.net/manuals/user-guide/snowsql-install-config.html]" -ErrorAction Stop } - if($PSCmdlet.ParameterSetName -match 'Connection$') + if ($PSCmdlet.ParameterSetName -match 'Connection$') { - if( -not $Connection ) + if ( -not $Connection ) { $Connection = Get-SnowSqlConnection } @@ -100,6 +106,10 @@ function Invoke-SnowSql { '--option', 'log_level=DEBUG' } + if ($timeout) + { + '--option', $('login_timeout=' + $timeout) + } if ($Path) { '--filename', $Path @@ -110,15 +120,23 @@ function Invoke-SnowSql } ) + $results = $null Write-Debug ("Executing [& '$snowsql' $snowSqlParam]" -f $snowsql) if ($PSCmdlet.ShouldProcess("Execute SnowSql on [$Endpoint] as [$($Credential.UserName)]. Use -Debug to see full command")) { - $env:SNOWSQL_PWD = $Credential.GetNetworkCredential().password - $results = & $snowsql @snowSqlParam | ConvertFrom-Csv + $env:SNOWSQL_PWD = $Credential.GetNetworkCredential().Password + try + { + $executeQuery = & $snowsql @snowSqlParam 2>&1 + $results = $executeQuery | ConvertFrom-Csv + } + catch + { + Write-Error ("An error occurred while executing a request [{0}]. Use -Debug to see full command" -f $_) + } $env:SNOWSQL_PWD = "" Write-Verbose "LastExitCode[$LastExitCode]" } - $results } } diff --git a/SnowSQL/public/Open-SnowSqlConnection.ps1 b/SnowSQL/public/Open-SnowSqlConnection.ps1 index ed9600d..32521fb 100644 --- a/SnowSQL/public/Open-SnowSqlConnection.ps1 +++ b/SnowSQL/public/Open-SnowSqlConnection.ps1 @@ -15,7 +15,7 @@ function Open-SnowSqlConnection #> [OutputType('SnowSql.Connection')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Implemented in Invoke-SnowSql")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Implemented in Invoke-SnowSql")] [cmdletbinding(SupportsShouldProcess)] param( # Snowflake endpoint (ex: contoso.east-us-2.azure) @@ -26,8 +26,19 @@ function Open-SnowSqlConnection # Credential for snowflake endpoint [Parameter(Mandatory)] [PSCredential] - $Credential + $Credential, + + # Login timeout in seconds + [int] + $Timeout = 10 ) + begin + { + if ($Endpoint -match '(http[s]?)(:\/\/)([^\s,]+)') + { + Write-Error ("Snowflake endpoint must not be a URL {0}" -f $Endpoint) -ErrorAction Stop + } + } end { @@ -42,10 +53,21 @@ function Open-SnowSqlConnection Query = '!help' ErrorAction = 'Stop' Connection = $SnowSqlConnection + timeout = $Timeout + } + if ($PSCmdlet.ShouldProcess("Execute SnowSql query [$($invokeSnowSqlSplat.query)] on [$Endpoint] as [$($Credential.UserName)]. Use -Debug to see full command")) + { + $Result = Invoke-SnowSql @invokeSnowSqlSplat + } + else + { + $Result = $true + } + if ($Result) + { + Write-Debug ("Success to connect to SnowSql endpoint {0}" -f $Endpoint) + $Script:SnowSqlConnection = $SnowSqlConnection + return $Script:SnowSqlConnection } - $null = Invoke-SnowSql @invokeSnowSqlSplat - $Script:SnowSqlConnection = $SnowSqlConnection - - return $Script:SnowSqlConnection } } diff --git a/Tests/Get-SnowSqlConnection.Tests.ps1 b/Tests/Get-SnowSqlConnection.Tests.ps1 index 2c574d2..8758097 100644 --- a/Tests/Get-SnowSqlConnection.Tests.ps1 +++ b/Tests/Get-SnowSqlConnection.Tests.ps1 @@ -2,7 +2,7 @@ InModuleScope SnowSQL { Describe 'Function Get-SnowSqlConnection' -Tag Build { It 'Get SnowSql Connection' { Mock Invoke-SnowSql -Verifiable {} - Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty) + Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty) -WhatIf Get-SnowSqlConnection | Should -Not -BeNullOrEmpty } } diff --git a/Tests/Open-SnowSqlConnection.Tests.ps1 b/Tests/Open-SnowSqlConnection.Tests.ps1 index e68b182..28fea3e 100644 --- a/Tests/Open-SnowSqlConnection.Tests.ps1 +++ b/Tests/Open-SnowSqlConnection.Tests.ps1 @@ -2,7 +2,7 @@ InModuleScope SnowSql { Describe 'Function Open-SnowSqlConnection' -Tag Build { It 'Open SnowSql Connection ' { Mock Invoke-SnowSql -Verifiable {} - Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty) + Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty) -Whatif } } } diff --git a/Tests/Project/Help.Tests.ps1 b/Tests/Project/Help.Tests.ps1 index 954cf88..0626657 100644 --- a/Tests/Project/Help.Tests.ps1 +++ b/Tests/Project/Help.Tests.ps1 @@ -1,6 +1,8 @@ $Script:ModuleRoot = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $Script:ModuleName = $Script:ModuleName = Get-ChildItem $ModuleRoot\*\*.psm1 | Select-object -ExpandProperty BaseName +$Script:SourceRoot = Join-Path -Path $ModuleRoot -ChildPath $ModuleName + Describe "Public commands have comment-based or external help" -Tags 'Build' { $functions = Get-Command -Module $ModuleName $help = foreach ($function in $functions) { @@ -11,20 +13,19 @@ Describe "Public commands have comment-based or external help" -Tags 'Build' { { Context $node.Name { It "Should have a Description or Synopsis" { - ($node.Description + $node.Synopsis) | Should Not BeNullOrEmpty + $node.Synopsis.Length + $node.Description.Text.Length | Should -BeGreaterOrEqual 1 } - It "Should have an Example" { - $node.Examples | Should Not BeNullOrEmpty + It "Should have an Example" { + $node.Examples | Should -Not -BeNullOrEmpty $node.Examples | Out-String | Should -Match ($node.Name) } - foreach ($parameter in $node.Parameters.Parameter) { if ($parameter -notmatch 'WhatIf|Confirm') { It "Should have a Description for Parameter [$($parameter.Name)]" { - $parameter.Description.Text | Should Not BeNullOrEmpty + $parameter.Description[0].Text.length | Should -BeGreaterOrEqual 1 } } } diff --git a/Tests/Project/Module.Tests.ps1 b/Tests/Project/Module.Tests.ps1 index f652dc4..411c5d5 100644 --- a/Tests/Project/Module.Tests.ps1 +++ b/Tests/Project/Module.Tests.ps1 @@ -6,7 +6,7 @@ $Script:SourceRoot = Join-Path -Path $ModuleRoot -ChildPath $ModuleName Describe "All commands pass PSScriptAnalyzer rules" -Tag 'Build' { $rules = "$ModuleRoot\ScriptAnalyzerSettings.psd1" $scripts = Get-ChildItem -Path $SourceRoot -Include '*.ps1', '*.psm1', '*.psd1' -Recurse | - Where-Object FullName -notmatch 'Classes' + Where-Object FullName -notmatch 'Classes' foreach ($script in $scripts) { @@ -18,14 +18,14 @@ Describe "All commands pass PSScriptAnalyzer rules" -Tag 'Build' { { It $rule.RuleName { $message = "{0} Line {1}: {2}" -f $rule.Severity, $rule.Line, $rule.Message - $message | Should Be "" + $message | Should -Be "" } } } else { It "Should not fail any rules" { - $results | Should BeNullOrEmpty + $results | Should -BeNullOrEmpty } } } @@ -39,7 +39,7 @@ Describe "Public commands have Pester tests" -Tag 'Build' { { $file = Get-ChildItem -Path "$ModuleRoot\Tests" -Include "$command.Tests.ps1" -Recurse It "Should have a Pester test for [$command]" { - $file.FullName | Should Not BeNullOrEmpty + $file.FullName | Should -Not -BeNullOrEmpty } } } diff --git a/build.ps1 b/build.ps1 index ec892fc..a45409e 100644 --- a/build.ps1 +++ b/build.ps1 @@ -20,7 +20,7 @@ Get-PackageProvider -Name 'NuGet' -ForceBootstrap | Out-Null Install-Module -Name $Script:Modules -Scope $Script:ModuleInstallScope -Force -SkipPublisherCheck -Set-BuildEnvironment +Set-BuildEnvironment -Force Get-ChildItem Env:BH* Get-ChildItem Env:APPVEYOR*