Skip to content

Commit

Permalink
Added Pester tests for $env:CustomAsDwInstallLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJohnT committed Jan 4, 2021
1 parent b07f704 commit 76c9440
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 18 deletions.
16 changes: 11 additions & 5 deletions DeployCube/public/Find-AnalysisServicesDeploymentExeLocations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ function Find-AnalysisServicesDeploymentExeLocations {
try {
[string]$ExeName = "Microsoft.AnalysisServices.Deployment.exe";
# Get SQL Server locations
$AnalysisServicesDeploymentExes = @();

#Up to v17 (140)
$AnalysisServicesDeploymentExes += Get-Childitem -Path "${env:ProgramFiles(x86)}\Microsoft SQL Server\*\Tools\Binn" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;
[System.IO.FileSystemInfo[]]$AnalysisServicesDeploymentExes = Get-Childitem -Path "${env:ProgramFiles(x86)}\Microsoft SQL Server\*\Tools\Binn" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;

#V18 (SSMS - 150)
$AnalysisServicesDeploymentExes += Get-Childitem -Path "${env:ProgramFiles(x86)}\Microsoft SQL Server Management Studio *\Common7" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;

# Custom install location defined by Environment variable CustomAsDwInstallLocation
$AnalysisServicesDeploymentExes += Get-Childitem -Path "${env:CustomAsDwInstallLocation}" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;

$CustomAsDwInstallLocation = [Environment]::GetEnvironmentVariable('CustomAsDwInstallLocation');
if ("$CustomAsDwInstallLocation" -ne "") {
if (Test-Path $CustomAsDwInstallLocation) {
$AnalysisServicesDeploymentExes += Get-Childitem -Path "$CustomAsDwInstallLocation\" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;
} else {
throw "Invalid custom environment variable path: CustomAsDwInstallLocation";
}
}

# list all the locations found
foreach ($AnalysisServicesDeploymentExe in $AnalysisServicesDeploymentExes) {
[string]$ProductVersion = $AnalysisServicesDeploymentExe.VersionInfo.ProductVersion.Substring(0,2);
Expand Down
22 changes: 15 additions & 7 deletions DeployCube/public/Get-AnalysisServicesDeploymentExePath.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,27 @@ function Get-AnalysisServicesDeploymentExePath {
[string]$Version
)

try {
#try {
$AnalysisServicesDeploymentExes = @();

[string] $ExeName = "Microsoft.AnalysisServices.Deployment.exe";
[string] $AnalysisServicesDeploymentExePath = $null;

# Location SQL Server 2017 and prior
$AnalysisServicesDeploymentExes = Get-Childitem -Path "${env:ProgramFiles(x86)}\Microsoft SQL Server\*\Tools\Binn" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;
[System.IO.FileSystemInfo[]]$AnalysisServicesDeploymentExes = Get-Childitem -Path "${env:ProgramFiles(x86)}\Microsoft SQL Server\*\Tools\Binn" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;

# Location SQL Server 2019 and greater (i.e. installed with SSMS)
$AnalysisServicesDeploymentExes += Get-Childitem -Path "${env:ProgramFiles(x86)}\Microsoft SQL Server Management Studio *\Common7\IDE" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;

# Custom install location defined by Environment variable CustomAsDwInstallLocation
$AnalysisServicesDeploymentExes += Get-Childitem -Path "${env:CustomAsDwInstallLocation}" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;
$CustomAsDwInstallLocation = [Environment]::GetEnvironmentVariable('CustomAsDwInstallLocation');
if ("$CustomAsDwInstallLocation" -ne "") {
if (Test-Path $CustomAsDwInstallLocation) {
$AnalysisServicesDeploymentExes += Get-Childitem -Path "$CustomAsDwInstallLocation\" -Recurse -Include $ExeName -ErrorAction SilentlyContinue;
} else {
throw "Invalid custom environment variable path: CustomAsDwInstallLocation";
}
}

foreach ($AnalysisServicesDeploymentExe in $AnalysisServicesDeploymentExes) {
$ExePath = $AnalysisServicesDeploymentExe.FullName;
Expand All @@ -81,10 +88,11 @@ function Get-AnalysisServicesDeploymentExePath {
}
}

}
catch {
Write-Error "Get-AnalysisServicesDeploymentExePath failed with error $Error";
}
#}
#catch {
# $ErrMsg = $PSItem.ToString();
# Write-Error "Get-AnalysisServicesDeploymentExePath failed with error $ErrMsg";
#}
return $AnalysisServicesDeploymentExePath;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<DeploymentTarget xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200">
<Database>MyCube</Database>
<Server>555ded22-e4c2-4658-993a-80ca20c95707</Server>
<ConnectionString>Data Source=555ded22-e4c2-4658-993a-80ca20c95707;Timeout=0;</ConnectionString>
<Server>c7289a72-9a61-4416-9fbb-2356f1a8e1a7</Server>
<ConnectionString>Data Source=c7289a72-9a61-4416-9fbb-2356f1a8e1a7;Timeout=0;</ConnectionString>
</DeploymentTarget>
Binary file not shown.
20 changes: 20 additions & 0 deletions test/Find-AnalysisServicesDeploymentExeLocations.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@
$CurrentFolder = Split-Path -Parent $PSScriptRoot;
$ModulePath = Resolve-Path "$CurrentFolder\DeployCube\DeployCube.psd1";
import-Module -Name $ModulePath;

function ResetEnv {
$value = [Environment]::GetEnvironmentVariable("CustomAsDwInstallLocation");
if ("$value" -ne "") {
Clear-Item -Path Env:CustomAsDwInstallLocation;
}
}
}


Describe "Find-AnalysisServicesDeploymentExeLocations" -Tag "Round1" {
Context "Should return output" {
It "Finds some version" {
ResetEnv;
( Find-AnalysisServicesDeploymentExeLocations ) | Should -Not -Be $null
$lines = Find-AnalysisServicesDeploymentExeLocations | Measure-Object;
$lines.Count | Should -Be 1;
}

It "Valid folder location and Microsoft.AnalysisServices.Deployment.exe present" {
ResetEnv;
$ExePath = Split-Path -Parent $PSScriptRoot;
$ExePath = Resolve-Path "$ExePath\examples\DeploymentWizard";
$env:CustomAsDwInstallLocation = $ExePath;

$lines = Find-AnalysisServicesDeploymentExeLocations | Measure-Object;
$lines.Count | Should -Be 2;
}
}
}
Expand Down
35 changes: 34 additions & 1 deletion test/Get-AnalysisServicesDeploymentExePath.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
BeforeAll {
$ModulePath = Split-Path -Parent $PSScriptRoot;
$ModulePath = Resolve-Path "$ModulePath\DeployCube\DeployCube.psd1";
import-Module -Name $ModulePath;
import-Module -Name $ModulePath;

function ResetEnv {
$value = [Environment]::GetEnvironmentVariable("CustomAsDwInstallLocation");
if ("$value" -ne "") {
Clear-Item -Path Env:CustomAsDwInstallLocation;
}
}

}

Expand All @@ -17,33 +24,59 @@ Describe "Get-AnalysisServicesDeploymentExePath" -Tag "Round1" {
Context "Finding Microsoft.AnalysisServices.Deployment.exe version" {

It "Finds version 15" {
ResetEnv;
( Get-AnalysisServicesDeploymentExePath -Version 15 ) -like "*Microsoft.AnalysisServices.Deployment.exe" | Should -Be $true
}

It "Does not find version 14" {
ResetEnv;
( Get-AnalysisServicesDeploymentExePath -Version 14 ) -like "*Microsoft.AnalysisServices.Deployment.exe" | Should -Be $false
}

It "Does not find version 13" {
ResetEnv;
( Get-AnalysisServicesDeploymentExePath -Version 13 ) -like "*Microsoft.AnalysisServices.Deployment.exe" | Should -Be $false
}

It "Does not find version 12" {
ResetEnv;
( Get-AnalysisServicesDeploymentExePath -Version 12 ) -like "*Microsoft.AnalysisServices.Deployment.exe" | Should -Be $false
}

It "Does not find version 11" {
ResetEnv;
( Get-AnalysisServicesDeploymentExePath -Version 11 ) -like "*Microsoft.AnalysisServices.Deployment.exe" | Should -Be $false
}

It "Unsupported version 10 so should Throw" {
ResetEnv;
{ Get-AnalysisServicesDeploymentExePath -Version 10 } | Should -Throw;
}

It "Invalid version XX should Throw" {
ResetEnv;
{ Get-AnalysisServicesDeploymentExePath -Version XX } | Should -Throw;
}

It "Valid folder but Microsoft.AnalysisServices.Deployment.exe is not present in folder" {
ResetEnv;
$env:CustomAsDwInstallLocation = $PSScriptRoot;
( Get-AnalysisServicesDeploymentExePath -Version 13 ) -like "*Microsoft.AnalysisServices.Deployment.exe" | Should -Be $false;
}

It "Invalid folder location for CustomAsDwInstallLocation" {
ResetEnv;
$env:CustomAsDwInstallLocation = $PSScriptRoot + "\xxx";
{ Get-AnalysisServicesDeploymentExePath -Version 13 } | Should -Throw;
}

It "Valid folder location and Microsoft.AnalysisServices.Deployment.exe present" {
ResetEnv;
$ExePath = Split-Path -Parent $PSScriptRoot;
$ExePath = Resolve-Path "$ExePath\examples\DeploymentWizard";
$env:CustomAsDwInstallLocation = $ExePath;
( Get-AnalysisServicesDeploymentExePath -Version 11 ) -like "*Microsoft.AnalysisServices.Deployment.exe" | Should -Be $true;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/Ping-SsasServer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Describe "Ping-SsasServer" -Tag "Round1" {
( Ping-SsasServer -Server "localhost" ) | Should -Be $true;
}

It "Azure servers are unsupported" {
It "Azure servers are unsupported by Ping-SsasServer" {
{ Ping-SsasServer -Server "asazure://uksouth.asazure.windows.net/xxx" } | Should -Throw;
}
}
Expand Down
21 changes: 19 additions & 2 deletions test/Select-AnalysisServicesDeploymentExeVersion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
$CurrentFolder = Split-Path -Parent $PSScriptRoot;
$ModulePath = Resolve-Path "$CurrentFolder\DeployCube\DeployCube.psd1";
import-Module -Name $ModulePath;
function ResetEnv {
$value = [Environment]::GetEnvironmentVariable("CustomAsDwInstallLocation");
if ("$value" -ne "") {
Clear-Item -Path Env:CustomAsDwInstallLocation;
}
}
ResetEnv;
}

Describe "Select-AnalysisServicesDeploymentExeVersion" -Tag "Round1" {
Expand Down Expand Up @@ -37,13 +44,23 @@ Describe "Select-AnalysisServicesDeploymentExeVersion" -Tag "Round1" {
Select-AnalysisServicesDeploymentExeVersion -PreferredVersion 11 | Should -Not -Be 11;
}

It "Unsupported AnalysisServicesDeploymentExe version 100 so should Throw" {
It "Now finds version 11" {
ResetEnv;
$ExePath = Split-Path -Parent $PSScriptRoot;
$ExePath = Resolve-Path "$ExePath\examples\DeploymentWizard";
$env:CustomAsDwInstallLocation = $ExePath;
Select-AnalysisServicesDeploymentExeVersion -PreferredVersion 11 | Should -Be 11;
}

It "Unsupported AnalysisServicesDeploymentExe version 10 so should Throw" {
{ Select-AnalysisServicesDeploymentExeVersion -PreferredVersion 10 } | Should -Throw;
}

It "Invalid version XXX so should throw" {
It "Invalid version XX so should throw" {
{ Select-AnalysisServicesDeploymentExeVersion -PreferredVersion XX } | Should -Throw;
}


}
}

Expand Down

0 comments on commit 76c9440

Please sign in to comment.