From 6b8587a30eac09fde3eadcd2718447b4b870b94e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 28 Mar 2019 09:29:24 -0400 Subject: [PATCH] Update Generic Tests --- Tests/Public/ZertoApiWrapper.Tests.ps1 | 42 ++++++++++++++++++-------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/Tests/Public/ZertoApiWrapper.Tests.ps1 b/Tests/Public/ZertoApiWrapper.Tests.ps1 index 529c086..b9f88f4 100644 --- a/Tests/Public/ZertoApiWrapper.Tests.ps1 +++ b/Tests/Public/ZertoApiWrapper.Tests.ps1 @@ -1,23 +1,39 @@ +$moduleName = "ZertoApiWrapper" $moduleFileName = "ZertoApiWrapper.psm1" $filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' +$docsPath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests[\\\/]Public', 'docs' $modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) - -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" +Import-Module $modulePath\$moduleFileName Describe "File Tests" { - $commands = Get-Command -Module ZertoApiWrapper | Select-Object -ExpandProperty Name + Remove-Module $moduleName -Force + Import-Module $modulePath\$moduleFileName + $commands = Get-Command -Module $moduleName | Select-Object -ExpandProperty Name foreach ($command in $commands) { + $externalHelpFile = "{0}/{1}.md" -f $docsPath, $command $path = "{0}/{1}.ps1" -f $filePath, $command - it "$command is backed by a file with the same name" { - $path | should exist + context "$command File Tests" { + it "$command is backed by a file with the same name" { + $path | should exist + } + it "$command file has openbraces on the same line as the statement" { + $content = Get-Content -Path $path + $openingBracesExist = $content | Where-Object {$_.Trim() -eq '{'} + if ($openingBracesExist) { + Write-Warning "Found the following opening brances on their own line:" + foreach ($openingBrace in $openingBracesExist) { + Write-Warning "Opening Brace on it's own line - $openingBrace" + } + } + $openingBracesExist | should benullorempty + } + it "$command has an external help file" { + $externalHelpFile | should exist + } + it "$command has the External Help File Defined" { + Get-Content -Path $path -First 1 | should be "<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>" + } } } -} \ No newline at end of file +}