Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@
#
# ------------------ PackageManagement Test -----------------------------------

$InternalGallery = "https://www.poshtestgallery.com/api/v2/"
$InternalSource = 'OneGetTestSource'
$gallery = "https://www.powershellgallery.com/api/v2"
$source = 'OneGetTestSource'

Describe "PackageManagement Acceptance Test" -Tags "Feature" {

BeforeAll{
Register-PackageSource -Name Nugettest -provider NuGet -Location https://www.nuget.org/api/v2 -Force

## Comment out this line because 'poshtestgallery.com' is down, tracked by https://github.com/PowerShell/PowerShell/issues/17019
## Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
$packageSource = Get-PackageSource -Location $gallery -ErrorAction SilentlyContinue
if ($packageSource) {
$source = $packageSource.Name
Comment thread
daxian-dbw marked this conversation as resolved.
Set-PackageSource -Name $source -Trusted
} else {
Register-PackageSource -Name $source -Location $gallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
}

$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
Expand All @@ -43,10 +49,9 @@ Describe "PackageManagement Acceptance Test" -Tags "Feature" {
$fpp | Should -Contain "PowerShellGet"
}

## Make this test pending because 'poshtestgallery.com' is down, tracked by https://github.com/PowerShell/PowerShell/issues/17019
It "install-packageprovider, Expect succeed" -Pending {
$ipp = (Install-PackageProvider -Name gistprovider -Force -Source $InternalSource -Scope CurrentUser).name
$ipp | Should -Contain "gistprovider"
It "install-packageprovider, Expect succeed" {
$ipp = (Install-PackageProvider -Name NanoServerPackage -Force -Source $source -Scope CurrentUser).name
$ipp | Should -Contain "NanoServerPackage"
}

It "Find-package" {
Expand Down
88 changes: 27 additions & 61 deletions test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
# no progress output during these tests
$ProgressPreference = "SilentlyContinue"

$RepositoryName = 'INTGallery'
$SourceLocation = 'https://www.poshtestgallery.com'
$RegisteredINTRepo = $false
$ContosoServer = 'ContosoServer'
$FabrikamServerScript = 'Fabrikam-ServerScript'
$RepositoryName = 'PSGallery'
$SourceLocation = 'https://www.powershellgallery.com'
$TestModule = 'newTestModule'
$TestScript = 'TestTestScript'
$Initialized = $false

#region Utility functions
Expand Down Expand Up @@ -93,30 +92,24 @@ function Initialize
if($repo)
{
$script:RepositoryName = $repo.Name
Set-PackageSource -Name $repo.Name -Trusted
}
else
{
Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -InstallationPolicy Trusted
$script:RegisteredINTRepo = $true
}
}

#endregion

function Remove-InstalledModules
{
Get-InstalledModule -Name $ContosoServer -AllVersions -ErrorAction SilentlyContinue | PowerShellGet\Uninstall-Module -Force
Get-InstalledModule -Name $TestModule -AllVersions -ErrorAction SilentlyContinue | PowerShellGet\Uninstall-Module -Force
}

Describe "PowerShellGet - Module tests" -tags "Feature" {

BeforeAll {
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
# These should be re-enabled when the issue is fixed
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:pending"] = $true
return

if ($script:Initialized -eq $false) {
Initialize
$script:Initialized = $true
Expand All @@ -128,39 +121,32 @@ Describe "PowerShellGet - Module tests" -tags "Feature" {
}

It "Should find a module correctly" {
$psgetModuleInfo = Find-Module -Name $ContosoServer -Repository $RepositoryName
$psgetModuleInfo.Name | Should -Be $ContosoServer
$psgetModuleInfo = Find-Module -Name $TestModule -Repository $RepositoryName
$psgetModuleInfo.Name | Should -Be $TestModule
$psgetModuleInfo.Repository | Should -Be $RepositoryName
}

It "Should install a module correctly to the required location with default CurrentUser scope" {
Install-Module -Name $ContosoServer -Repository $RepositoryName
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
Install-Module -Name $TestModule -Repository $RepositoryName
$installedModuleInfo = Get-InstalledModule -Name $TestModule

$installedModuleInfo | Should -Not -BeNullOrEmpty
$installedModuleInfo.Name | Should -Be $ContosoServer
$installedModuleInfo.Name | Should -Be $TestModule
$installedModuleInfo.InstalledLocation.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue

$module = Get-Module $ContosoServer -ListAvailable
$module.Name | Should -Be $ContosoServer
$module = Get-Module $TestModule -ListAvailable
$module.Name | Should -Be $TestModule
$module.ModuleBase | Should -Be $installedModuleInfo.InstalledLocation
}

AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
Remove-InstalledModules
}
}

Describe "PowerShellGet - Module tests (Admin)" -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {

BeforeAll {
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
# These should be re-enabled when the issue is fixed
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:pending"] = $true
return

if ($script:Initialized -eq $false) {
Initialize
$script:Initialized = $true
Expand All @@ -172,38 +158,31 @@ Describe "PowerShellGet - Module tests (Admin)" -Tags @('Feature', 'RequireAdmin
}

It "Should install a module correctly to the required location with AllUsers scope" {
Install-Module -Name $ContosoServer -Repository $RepositoryName -Scope AllUsers
$installedModuleInfo = Get-InstalledModule -Name $ContosoServer
Install-Module -Name $TestModule -Repository $RepositoryName -Scope AllUsers
$installedModuleInfo = Get-InstalledModule -Name $TestModule

$installedModuleInfo | Should -Not -BeNullOrEmpty
$installedModuleInfo.Name | Should -Be $ContosoServer
$installedModuleInfo.Name | Should -Be $TestModule
$installedModuleInfo.InstalledLocation.StartsWith($script:programFilesModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue

$module = Get-Module $ContosoServer -ListAvailable
$module.Name | Should -Be $ContosoServer
$module = Get-Module $TestModule -ListAvailable
$module.Name | Should -Be $TestModule
$module.ModuleBase | Should -Be $installedModuleInfo.InstalledLocation
}

AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
Remove-InstalledModules
}
}

function Remove-InstalledScripts
{
Get-InstalledScript -Name $FabrikamServerScript -ErrorAction SilentlyContinue | Uninstall-Script -Force
Get-InstalledScript -Name $TestScript -ErrorAction SilentlyContinue | Uninstall-Script -Force
}

Describe "PowerShellGet - Script tests" -tags "Feature" {

BeforeAll {
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
# These should be re-enabled when the issue is fixed
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:pending"] = $true
return

if ($script:Initialized -eq $false) {
Initialize
$script:Initialized = $true
Expand All @@ -215,35 +194,28 @@ Describe "PowerShellGet - Script tests" -tags "Feature" {
}

It "Should find a script correctly" {
$psgetScriptInfo = Find-Script -Name $FabrikamServerScript -Repository $RepositoryName
$psgetScriptInfo.Name | Should -Be $FabrikamServerScript
$psgetScriptInfo = Find-Script -Name $TestScript -Repository $RepositoryName
$psgetScriptInfo.Name | Should -Be $TestScript
$psgetScriptInfo.Repository | Should -Be $RepositoryName
}

It "Should install a script correctly to the required location with default CurrentUser scope" {
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -NoPathUpdate
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
Install-Script -Name $TestScript -Repository $RepositoryName -NoPathUpdate
$installedScriptInfo = Get-InstalledScript -Name $TestScript

$installedScriptInfo | Should -Not -BeNullOrEmpty
$installedScriptInfo.Name | Should -Be $FabrikamServerScript
$installedScriptInfo.Name | Should -Be $TestScript
$installedScriptInfo.InstalledLocation.StartsWith($script:MyDocumentsScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue
}

AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
Remove-InstalledScripts
}
}

Describe "PowerShellGet - Script tests (Admin)" -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {

BeforeAll {
# Setting all It block to pending as the test fail due to https://github.com/PowerShell/PowerShell/issues/17019
# These should be re-enabled when the issue is fixed
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:pending"] = $true
return

if ($script:Initialized -eq $false) {
Initialize
$script:Initialized = $true
Expand All @@ -255,16 +227,15 @@ Describe "PowerShellGet - Script tests (Admin)" -Tags @('Feature', 'RequireAdmin
}

It "Should install a script correctly to the required location with AllUsers scope" {
Install-Script -Name $FabrikamServerScript -Repository $RepositoryName -NoPathUpdate -Scope AllUsers
$installedScriptInfo = Get-InstalledScript -Name $FabrikamServerScript
Install-Script -Name $TestScript -Repository $RepositoryName -NoPathUpdate -Scope AllUsers
$installedScriptInfo = Get-InstalledScript -Name $TestScript

$installedScriptInfo | Should -Not -BeNullOrEmpty
$installedScriptInfo.Name | Should -Be $FabrikamServerScript
$installedScriptInfo.Name | Should -Be $TestScript
$installedScriptInfo.InstalledLocation.StartsWith($script:ProgramFilesScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should -BeTrue
}

AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
Remove-InstalledScripts
}
}
Expand Down Expand Up @@ -300,8 +271,3 @@ Describe 'PowerShellGet Type tests' -tags @('CI') {
}
}
}

if($RegisteredINTRepo)
{
Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue | Unregister-PSRepository
}