2016-08-27 01:58:22 +02:00
|
|
|
|
$RepositoryName = 'INTGallery'
|
|
|
|
|
$SourceLocation = 'https://dtlgalleryint.cloudapp.net'
|
|
|
|
|
$RegisteredINTRepo = $false
|
|
|
|
|
$ContosoServer = 'ContosoServer'
|
|
|
|
|
$FabrikamServerScript = 'Fabrikam-ServerScript'
|
|
|
|
|
|
|
|
|
|
#region Utility functions
|
|
|
|
|
|
|
|
|
|
function IsInbox { $PSHOME.EndsWith('\WindowsPowerShell\v1.0', [System.StringComparison]::OrdinalIgnoreCase) }
|
|
|
|
|
function IsWindows { $PSVariable = Get-Variable -Name IsWindows -ErrorAction Ignore; return (-not $PSVariable -or $PSVariable.Value) }
|
|
|
|
|
function IsCoreCLR { $PSVariable = Get-Variable -Name IsCoreCLR -ErrorAction Ignore; return ($PSVariable -and $PSVariable.Value) }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Install locations for modules and scripts
|
|
|
|
|
|
|
|
|
|
if(IsInbox)
|
|
|
|
|
{
|
|
|
|
|
$script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell"
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$script:ProgramFilesPSPath = $PSHome
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(IsInbox)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$script:MyDocumentsFolderPath = [Environment]::GetFolderPath("MyDocuments")
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
$script:MyDocumentsFolderPath = $null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath)
|
|
|
|
|
{
|
|
|
|
|
Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath "WindowsPowerShell"
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
elseif(IsWindows)
|
|
|
|
|
{
|
|
|
|
|
$script:MyDocumentsPSPath = Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath 'Documents\PowerShell'
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$script:MyDocumentsPSPath = Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath '.local/share/powershell'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$script:ProgramFilesModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath 'Modules'
|
|
|
|
|
$script:MyDocumentsModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath 'Modules'
|
|
|
|
|
|
|
|
|
|
$script:ProgramFilesScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath 'Scripts'
|
|
|
|
|
$script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath 'Scripts'
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Register a test repository
|
|
|
|
|
|
|
|
|
|
$repo = Get-PSRepository -ErrorAction SilentlyContinue |
|
|
|
|
|
Where-Object {$_.SourceLocation.StartsWith($SourceLocation, [System.StringComparison]::OrdinalIgnoreCase)}
|
|
|
|
|
if($repo)
|
|
|
|
|
{
|
|
|
|
|
$RepositoryName = $repo.Name
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -InstallationPolicy Trusted
|
|
|
|
|
$RegisteredINTRepo = $true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-09-14 02:45:38 +02:00
|
|
|
|
function Remove-InstalledModules
|
|
|
|
|
{
|
|
|
|
|
Get-InstalledModule -Name $ContosoServer -AllVersions -ErrorAction SilentlyContinue | Uninstall-Module -Force
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 21:34:10 +02:00
|
|
|
|
Describe "PowerShellGet - Module tests" -tags "Feature" {
|
2016-08-27 01:58:22 +02:00
|
|
|
|
|
|
|
|
|
BeforeEach {
|
2016-09-14 02:45:38 +02:00
|
|
|
|
Remove-InstalledModules
|
2016-08-27 01:58:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should find a module correctly" {
|
|
|
|
|
$psgetModuleInfo = Find-Module -Name $ContosoServer -Repository $RepositoryName
|
|
|
|
|
$psgetModuleInfo.Name | Should Be $ContosoServer
|
|
|
|
|
$psgetModuleInfo.Repository | Should Be $RepositoryName
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 02:45:38 +02:00
|
|
|
|
It "Should install a module correctly to the required location with CurrentUser scope" {
|
|
|
|
|
Install-Module -Name $ContosoServer -Repository $RepositoryName -Scope CurrentUser
|
2016-08-27 01:58:22 +02:00
|
|
|
|
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
|
|
|
|
|
|
2016-09-14 02:45:38 +02:00
|
|
|
|
$installedModuleInfo | Should Not Be $null
|
2016-08-27 01:58:22 +02:00
|
|
|
|
$installedModuleInfo.Name | Should Be $ContosoServer
|
2016-09-14 02:45:38 +02:00
|
|
|
|
$installedModuleInfo.InstalledLocation.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
|
2016-08-27 01:58:22 +02:00
|
|
|
|
|
|
|
|
|
$module = Get-Module $ContosoServer -ListAvailable
|
|
|
|
|
$module.Name | Should be $ContosoServer
|
|
|
|
|
$module.ModuleBase | Should Be $installedModuleInfo.InstalledLocation
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 02:45:38 +02:00
|
|
|
|
AfterAll {
|
|
|
|
|
Remove-InstalledModules
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdminOnWindows') {
|
|
|
|
|
|
|
|
|
|
BeforeEach {
|
|
|
|
|
Remove-InstalledModules
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should install a module correctly to the required location with default AllUsers scope" {
|
|
|
|
|
Install-Module -Name $ContosoServer -Repository $RepositoryName
|
2016-08-27 01:58:22 +02:00
|
|
|
|
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
|
|
|
|
|
|
|
|
|
|
$installedModuleInfo | Should Not Be $null
|
|
|
|
|
$installedModuleInfo.Name | Should Be $ContosoServer
|
2016-09-14 02:45:38 +02:00
|
|
|
|
$installedModuleInfo.InstalledLocation.StartsWith($script:programFilesModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
|
2016-08-27 01:58:22 +02:00
|
|
|
|
|
|
|
|
|
$module = Get-Module $ContosoServer -ListAvailable
|
|
|
|
|
$module.Name | Should be $ContosoServer
|
|
|
|
|
$module.ModuleBase | Should Be $installedModuleInfo.InstalledLocation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterAll {
|
2016-09-14 02:45:38 +02:00
|
|
|
|
Remove-InstalledModules
|
2016-08-27 01:58:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 02:45:38 +02:00
|
|
|
|
function Remove-InstalledScripts
|
|
|
|
|
{
|
|
|
|
|
Get-InstalledScript -Name $FabrikamServerScript -ErrorAction SilentlyContinue | Uninstall-Script -Force
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 21:34:10 +02:00
|
|
|
|
Describe "PowerShellGet - Script tests" -tags "Feature" {
|
2016-08-27 01:58:22 +02:00
|
|
|
|
|
|
|
|
|
BeforeEach {
|
2016-09-14 02:45:38 +02:00
|
|
|
|
Remove-InstalledScripts
|
2016-08-27 01:58:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should find a script correctly" {
|
|
|
|
|
$psgetScriptInfo = Find-Script -Name $FabrikamServerScript -Repository $RepositoryName
|
|
|
|
|
$psgetScriptInfo.Name | Should Be $FabrikamServerScript
|
|
|
|
|
$psgetScriptInfo.Repository | Should Be $RepositoryName
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 02:45:38 +02:00
|
|
|
|
It "Should install a script correctly to the required location with CurrentUser scope" {
|
|
|
|
|
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -Scope CurrentUser -NoPathUpdate
|
2016-08-27 01:58:22 +02:00
|
|
|
|
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
|
|
|
|
|
|
|
|
|
|
$installedScriptInfo | Should Not Be $null
|
|
|
|
|
$installedScriptInfo.Name | Should Be $FabrikamServerScript
|
2016-09-14 02:45:38 +02:00
|
|
|
|
$installedScriptInfo.InstalledLocation.StartsWith($script:MyDocumentsScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
|
2016-08-27 01:58:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 02:45:38 +02:00
|
|
|
|
AfterAll {
|
|
|
|
|
Remove-InstalledScripts
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Describe "PowerShellGet - Script tests (Admin)" -tags @('Feature', 'RequireAdminOnWindows') {
|
|
|
|
|
|
|
|
|
|
BeforeEach {
|
|
|
|
|
Remove-InstalledScripts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should install a script correctly to the required location with default AllUsers scope" {
|
|
|
|
|
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -NoPathUpdate
|
2016-08-27 01:58:22 +02:00
|
|
|
|
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
|
|
|
|
|
|
|
|
|
|
$installedScriptInfo | Should Not Be $null
|
|
|
|
|
$installedScriptInfo.Name | Should Be $FabrikamServerScript
|
2016-09-14 02:45:38 +02:00
|
|
|
|
$installedScriptInfo.InstalledLocation.StartsWith($script:ProgramFilesScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
|
2016-08-27 01:58:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterAll {
|
2016-09-14 02:45:38 +02:00
|
|
|
|
Remove-InstalledScripts
|
2016-08-27 01:58:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($RegisteredINTRepo)
|
|
|
|
|
{
|
|
|
|
|
Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue | Unregister-PSRepository
|
|
|
|
|
}
|