Import source-depot tests for PackageManagement
This commit is contained in:
parent
cdb9a96d9d
commit
55b8cd1da6
|
@ -0,0 +1,287 @@
|
|||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# ------------------ PackageManagement Test -----------------------------------
|
||||
ipmo "$PSScriptRoot\utility.psm1"
|
||||
$InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Actual Tests:
|
||||
|
||||
Describe "find-packageprovider" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
BeforeAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
install-PackageProvider -name nuget -force
|
||||
}
|
||||
AfterAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
|
||||
#make sure the package repository exists
|
||||
$a=Get-PackageSource -force| select Location, ProviderName
|
||||
|
||||
$found = $false
|
||||
foreach ($item in $a)
|
||||
{
|
||||
#name contains "." foo.bar for example for the registered sources internally
|
||||
if(($item.ProviderName -eq "PowerShellGet") -and ($item.Location -eq $InternalGallery))
|
||||
{
|
||||
$found = $true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if(-not $found)
|
||||
{
|
||||
Register-PackageSource -Name 'OneGetTestSource' -Location $InternalGallery -ProviderName 'PowerShellGet' -ForceBootstrap -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
It "find-packageprovider without any parameters, Expect succeed" {
|
||||
$a = (Find-PackageProvider -force).name
|
||||
$a -contains "TSDProvider" | should be $true
|
||||
$a -contains "nuget" | should be $true
|
||||
}
|
||||
|
||||
It "find-packageprovider -name, Expect succeed" {
|
||||
$a = (Find-PackageProvider -name nuget).name
|
||||
$a -contains "GistProvider" | should be $false
|
||||
$a -contains "nuget" | should be $true
|
||||
}
|
||||
|
||||
It "find-packageprovider -name with wildcards, Expect succeed" {
|
||||
$a = (Find-PackageProvider -name gist*).name
|
||||
$a -contains "GistProvider" | should be $true
|
||||
$a -contains "nuget" | should be $false
|
||||
}
|
||||
|
||||
It "find-packageprovider -name with wildcards, Expect succeed" {
|
||||
$a = (Find-PackageProvider -name nu*).name
|
||||
$a -contains "GistProvider" | should be $false
|
||||
$a -contains "nuget" | should be $true
|
||||
}
|
||||
|
||||
It "find-packageprovider -name array, Expect succeed" {
|
||||
$names=@("gistprovider", "TSD*")
|
||||
|
||||
$a = (Find-PackageProvider -name $names).name
|
||||
$a -contains "GistProvider" | should be $true
|
||||
$a -contains "TSDProvider" | should be $true
|
||||
}
|
||||
|
||||
It "find-packageprovider -allversions, Expect succeed" {
|
||||
$a = (Find-PackageProvider -allversions)
|
||||
|
||||
$a.Name -contains "TSDProvider" | should be $true
|
||||
$a.Name -contains "nuget" | should be $true
|
||||
$a.Count -gt 1 | should be $true
|
||||
}
|
||||
|
||||
It "find-packageprovider -name -allversions, Expect succeed" {
|
||||
$a = (Find-PackageProvider -name TSDProvider -AllVersions).name
|
||||
$a -contains "TSDProvider" | should be $true
|
||||
|
||||
$b = (Find-PackageProvider -name TSDP* -AllVersions).name
|
||||
$b.Count -ge $a.Count | should be $true
|
||||
}
|
||||
|
||||
|
||||
It "EXPECTED: success 'find-packageprovider nuget -allVersions'" {
|
||||
$a = find-packageprovider -name nuget -allVersions
|
||||
$a.Count -ge 5| should be $true
|
||||
|
||||
$b = find-packageprovider -allVersions
|
||||
$b.Count -gt $a.Count| should be $true
|
||||
}
|
||||
|
||||
It "find-packageprovider -Source, Expect succeed" {
|
||||
$a = (Find-PackageProvider -source $InternalGallery).name
|
||||
$a -contains "TSDProvider" | should be $true
|
||||
$a -contains "nuget" | should be $false
|
||||
}
|
||||
|
||||
It "find-packageprovider -Source -Name, Expect succeed" {
|
||||
$a = (Find-PackageProvider -name gistprovider -source $InternalGallery).name
|
||||
$a -contains "gistprovider" | should be $true
|
||||
$a -contains "nuget" | should be $false
|
||||
}
|
||||
It "find-packageprovider -Name with dependencies, Expect succeed" {
|
||||
# gistprovider 1.5 depends on tsdprovider 0.2
|
||||
$a = (Find-PackageProvider -name gistprovider -RequiredVersion 1.5 -source $InternalGallery -IncludeDependencies)
|
||||
$a.Name -contains "gistprovider" | should be $true
|
||||
$a.Name -contains "tsdprovider" | should be $true
|
||||
}
|
||||
|
||||
It "find-install-packageprovider with PowerShell provider, Expect succeed" {
|
||||
$provider= find-packageprovider -name TSDProvider -MinimumVersion 0.1 -MaximumVersion 0.2 -Source $InternalGallery
|
||||
$provider | ?{ $_.Version -eq "0.2" } | should not BeNullOrEmpty
|
||||
|
||||
$a=install-packageprovider -name TSDProvider -MinimumVersion 0.1 -MaximumVersion 0.2 -Force -Source $InternalGallery
|
||||
$a.Name | should match "TSDProvider"
|
||||
$a.Version | should match "0.2"
|
||||
}
|
||||
|
||||
It "find-install-packageprovider nuget, Expect succeed" {
|
||||
$provider= find-packageprovider -name nuget -MinimumVersion 2.8.5.1 -MaximumVersion 2.8.5.123
|
||||
|
||||
$provider | ?{ $_.Version -eq "2.8.5.122" } | should not BeNullOrEmpty
|
||||
$provider.Count -eq 1 | should be $true
|
||||
|
||||
$a=install-packageprovider -name nuget -MinimumVersion 2.8.5.1 -MaximumVersion 2.8.5.123 -Force
|
||||
$a.Name | should match "nuget"
|
||||
$a.Version | should match "2.8.5.122"
|
||||
|
||||
$b= Get-PackageProvider -ListAvailable
|
||||
$b | ?{ $_.Version -eq "2.8.5.122" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Describe "Find-Package With FilterOnTag" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
BeforeAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
install-PackageProvider -name nuget -force
|
||||
}
|
||||
AfterAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
|
||||
it "EXPECTED: Find a package with FilterOnTag" {
|
||||
|
||||
$a=find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag Provider
|
||||
$a.name | should match "GistProvider"
|
||||
}
|
||||
|
||||
it "EXPECTED: Find a package with array of FilterOnTags" {
|
||||
|
||||
$a=find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag @('Provider','PackageManagement')
|
||||
$a.name | should match "GistProvider"
|
||||
|
||||
}
|
||||
|
||||
it "EXPECTED: Find a package with a bad tag" {
|
||||
$Error.Clear()
|
||||
find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag Pro -ErrorAction SilentlyContinue -ErrorVariable ev
|
||||
$ev.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
|
||||
}
|
||||
|
||||
it "EXPECTED: Find a package with a bad tag" {
|
||||
$Error.Clear()
|
||||
find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag Providerrrrrr -ErrorAction SilentlyContinue -ErrorVariable ev
|
||||
$ev.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Find-PackageProvider with Versions" -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
<# Nuget
|
||||
2.8.5.127
|
||||
2.8.5.122
|
||||
2.8.5.120
|
||||
2.8.5.101
|
||||
2.8.5.24#>
|
||||
|
||||
It "EXPECTED: success 'Find a provider -requiredVersion 3.5'" {
|
||||
(find-packageprovider -name Nuget -RequiredVersion 2.8.5.122).Version.ToString() | should match "2.8.5.122"
|
||||
}
|
||||
|
||||
|
||||
It "EXPECTED: success 'find a provider with MinimumVersion and MaximumVersion'" {
|
||||
(find-packageprovider -name nuget -MinimumVersion 2.8.5.105 -MaximumVersion 2.8.5.123).Version.ToString() | should match "2.8.5.122"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'find a provider with MaximumVersion'" {
|
||||
(find-packageprovider -name nuget -MaximumVersion 2.8.5.122).Version -contains "2.8.5.122" | should be $true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Describe "find-packageprovider Error Cases" -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
AfterAll {
|
||||
$x =Get-PackageSource -Name OneGetTestSource -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
if($x)
|
||||
{
|
||||
Unregister-PackageSource -Name OneGetTestSource
|
||||
}
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when inputing a bad version format" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name Gistprovider -RequiredVersion BOGUSVERSION -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "InvalidVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MinimumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MaximumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MaximumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with a MinimumVersion greater than MaximumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name nuget -MaximumVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with MinimumVersion that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name gistprovider -MinimumVersion 20.2 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with MaximumVersion that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name gistprovider -MaximumVersion 0.1 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider that has name with wildcard and version" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name "AnyName*" -RequiredVersion 4.5 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "MultipleNamesWithVersionNotAllowed,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider that has name with wildcard and version" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'find-packageprovider -name "AnyName" -RequiredVersion 4.5 -allVersions -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "AllVersionsCannotBeUsedWithOtherVersionParameters,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# ------------------ PackageManagement Test ----------------------------------------------
|
||||
ipmo "$PSScriptRoot\utility.psm1"
|
||||
|
||||
$nuget = "nuget"
|
||||
$source = "http://www.nuget.org/api/v2/"
|
||||
$destination = "$env:tmp\GetPackageTests"
|
||||
|
||||
# Bootstrap the provider
|
||||
Get-PackageProvider -Name $nuget -Force
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Actual Tests:
|
||||
|
||||
Describe "Get-package" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "EXPECTED: Get-package accepts array of strings for -providername parameter" {
|
||||
$x = (get-package -providername Programs,Msi)
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Get-package with version parameter - valid scenarios" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "Get-package supports -AllVersions parameter" {
|
||||
$outputWithAllVersions = (Get-Package -providername Programs,Msi -AllVersions)
|
||||
$outputWithoutAllVersions = (Get-Package -providername Programs,Msi)
|
||||
$outputWithAllVersions.count -ge $outputWithoutAllVersions.count | should be $true
|
||||
|
||||
}
|
||||
|
||||
It "E2E: Get-package supports -AllVersions parameter for a specific package - with multiple versions from Nuget" {
|
||||
($foundPackages = Find-Package -Name "adept.nugetrunner" -Provider $nuget -Source $source -AllVersions)
|
||||
|
||||
foreach ($package in $foundPackages)
|
||||
{
|
||||
($package | Install-Package -Destination $destination -Force)
|
||||
}
|
||||
|
||||
$installedPackages = (Get-Package -Name "adept.nugetrunner" -Provider $nuget -Destination $destination -AllVersions)
|
||||
$installedPackages.Name | should be "adept.nugetrunner"
|
||||
$installedPackages.Count -eq $foundPackages.Count | should be $true
|
||||
|
||||
# check that getting attributes from meta is not case sensitive
|
||||
$packageToInspect = $installedPackages[0]
|
||||
|
||||
$firstDescr = $packageToInspect.Meta.Attributes["Description"]
|
||||
# the description should not be null
|
||||
[string]::IsNullOrWhiteSpace($firstDescr) | should be $false
|
||||
$secondDescr = $packageToInspect.Meta.Attributes["dEsCriPtIoN"]
|
||||
|
||||
# the 2 descriptions should be the same
|
||||
$firstDescr -eq $secondDescr | should be $true
|
||||
|
||||
if (Test-Path $destination\adept.nugetrunner*) {
|
||||
(Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Get-package with version parameter - Error scenarios" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "Get-package -AllVersions -- Cannot be used with other version parameters" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'Get-Package -AllVersions -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "AllVersionsCannotBeUsedWithOtherVersionParameters,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage"
|
||||
|
||||
}
|
||||
|
||||
It "Get-package -RequiredVersion -- Cannot be used with Min/Max version parameters" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'Get-Package -RequiredVersion 1.0 -MinimumVersion 2.0 -MaximumVersion 3.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage"
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# ------------------ PackageManagement Test ----------------------------------------------
|
||||
ipmo "$PSScriptRoot\utility.psm1"
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Actual Tests:
|
||||
|
||||
Describe "get-packageprovider" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "lists package providers installed" {
|
||||
$x = (get-packageprovider -name "nuget" -ForceBootstrap).name | should match "nuget"
|
||||
}
|
||||
|
||||
It "lists package providers installed" {
|
||||
$x = (get-packageprovider -name "nuget" -verbose -Force).name | should match "nuget"
|
||||
}
|
||||
|
||||
It "EXPECTED: Gets The 'Programs' Package Provider" {
|
||||
$x = (get-packageprovider -name "Programs").name | should match "Programs"
|
||||
}
|
||||
|
||||
It "EXPECTED: Gets The 'P*' Package Provider" {
|
||||
$x = (get-packageprovider -name "P*").name.Contains('PowerShellGet')| should be $true
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'get-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for multiple providers that do not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'get-packageprovider -name NOT_EXISTS,NOT_EXISTS2 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for multiple providers that do not exist -list" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'get-packageprovider -name NOT_EXISTS,NOT_EXISTS2 -ListAvailable -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns swidtag conformed object for powershell-based provider" {
|
||||
$onegettest = (Get-PackageProvider OneGetTest -ListAvailable | Where-Object {$_.Version.ToString() -eq "9.9.0.0"} | Select -First 1)
|
||||
|
||||
$onegettest.Links.Count | should be 3
|
||||
|
||||
$found = $false
|
||||
|
||||
foreach ($link in $onegettest.Links)
|
||||
{
|
||||
if ($link.HRef.ToString() -match "http://oneget.org/icon" -and $link.Relationship -match "icon")
|
||||
{
|
||||
$found = $true
|
||||
}
|
||||
}
|
||||
|
||||
$found | should be $true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Describe "happy" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "looks for packages in bootstrap" {
|
||||
(find-package -provider bootstrap).Length | write-host
|
||||
}
|
||||
|
||||
It "does something else" {
|
||||
$false | should be $false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Describe "Get-PackageProvider with list" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "lists package providers installed" {
|
||||
$x = (Get-PackageProvider).Count -gt 1 | should be $true
|
||||
$y = (Get-PackageProvider -ListAvailable).Count -gt $x | should be $true
|
||||
}
|
||||
|
||||
It "List two providers" {
|
||||
(get-packageprovider -name "OneGetTest" -ListAvailable).name | should match "OneGetTest"
|
||||
(get-packageprovider -name "PowerShellGet" -ListAvailable).name | should match "PowerShellGet"
|
||||
|
||||
$providers = get-packageprovider -Name OneGetTest, PowerShellGet -ListAvailable
|
||||
|
||||
$providers | ?{ $_.name -eq "OneGetTest" } | should not BeNullOrEmpty
|
||||
|
||||
$providers | ?{ $_.name -eq "PowerShellGet" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "List two providers with wildcard chars" {
|
||||
$providers = get-packageprovider -Name OneGetTest* -ListAvailable
|
||||
|
||||
$providers | ?{ $_.name -eq "OneGetTest" } | should not BeNullOrEmpty
|
||||
#all versions of the OneGetTest provider should be displayed
|
||||
$providers.Count -ge 3 | should be $true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,415 @@
|
|||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# ------------------ PackageManagement Test ----------------------------------------------
|
||||
ipmo "$PSScriptRoot\utility.psm1"
|
||||
|
||||
$ProgramProviderInstalledPath = "$Env:ProgramFiles\PackageManagement\ProviderAssemblies"
|
||||
|
||||
$LocalAppData = [Environment]::GetFolderPath("LocalApplicationData")
|
||||
$UserProviderInstalledPath = "$($LocalAppData)\PackageManagement\ProviderAssemblies"
|
||||
|
||||
$ProgramModulePath = "$Env:ProgramFiles\WindowsPowerShell\Modules"
|
||||
|
||||
$mydocument = [Environment]::GetFolderPath("MyDocuments")
|
||||
$UserModuleFolder = "$($mydocument)\WindowsPowerShell\Modules"
|
||||
|
||||
$InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/"
|
||||
$InternalSource = 'OneGetTestSource'
|
||||
|
||||
#make sure the package repository exists
|
||||
$a=Get-PackageSource -ForceBootstrap| select Name, Location, ProviderName
|
||||
|
||||
$found = $false
|
||||
foreach ($item in $a)
|
||||
{
|
||||
#name contains "." foo.bar for example for the registered sources internally
|
||||
if($item.ProviderName -eq "PowerShellGet")
|
||||
{
|
||||
if ($item.Location -eq $InternalGallery) {
|
||||
Unregister-PackageSource $item.Name -Provider "PowerShellGet" -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Actual Tests:
|
||||
|
||||
Describe "import-packageprovider" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "Import -force 'PowerShellGet', a builtin package provider, Expect succeed" {
|
||||
#avoid popup for installing nuget-any.exe
|
||||
Find-PackageProvider -force
|
||||
(Import-PackageProvider 'PowerShellGet' -verbose -force).name | should match "PowerShellGet"
|
||||
}
|
||||
|
||||
|
||||
It "Import a PowerShell package provider Expect succeed" {
|
||||
(get-packageprovider -name "OneGetTest" -list).name | should match "OneGetTest"
|
||||
$x = PowerShell '(Import-PackageProvider OneGetTest -WarningAction SilentlyContinue).Name'
|
||||
$x | should match "OneGetTest"
|
||||
|
||||
$x = PowerShell '(Import-PackageProvider OneGetTest -WarningAction SilentlyContinue -force).Name'
|
||||
$x | should match "OneGetTest"
|
||||
}
|
||||
|
||||
It "Import 'OneGetTestProvider' CSharp package provider with filePath from programs folder, Expect succeed" {
|
||||
|
||||
$path = "$($ProgramProviderInstalledPath)\Microsoft.PackageManagement.OneGetTestProvider.dll"
|
||||
$path | should Exist
|
||||
|
||||
$job=Start-Job -ScriptBlock {
|
||||
param($path) import-packageprovider -name $path;
|
||||
} -ArgumentList @($path)
|
||||
|
||||
$a= $job | Receive-Job -Wait
|
||||
$a.Name | should match "OneGetTestProvider"
|
||||
|
||||
}
|
||||
|
||||
It "Import 'PSChained1Provider' PowerShell package provider with filePath from programfiles folder, Expect succeed" {
|
||||
|
||||
$path = "$($ProgramModulePath)\PSChained1Provider.psm1"
|
||||
$path | should Exist
|
||||
|
||||
$job=Start-Job -ScriptBlock {
|
||||
param($path) import-packageprovider -name $path;
|
||||
} -ArgumentList @($path)
|
||||
|
||||
$a= $job | Receive-Job -Wait
|
||||
$a.Name | should match "PSChained1Provider"
|
||||
}
|
||||
|
||||
|
||||
It "Import a CSharp package provider with filePath from user folder -force, Expect succeed" {
|
||||
$path = "$($UserProviderInstalledPath)\Microsoft.PackageManagement.OneGetTestProvider.dll"
|
||||
$path | should Exist
|
||||
|
||||
$job=Start-Job -ScriptBlock {
|
||||
param($path) import-packageprovider -name $path;
|
||||
} -ArgumentList @($path)
|
||||
|
||||
$a= $job | Receive-Job -Wait
|
||||
$a.Name | should match "OneGetTestProvider"
|
||||
}
|
||||
|
||||
It "Import a PowerShell package provider with filePath from user folder -force, Expect succeed" {
|
||||
|
||||
$path = "$($UserModuleFolder)\PSChained1Provider.psm1"
|
||||
$path | should Exist
|
||||
|
||||
$job=Start-Job -ScriptBlock {
|
||||
param($path) import-packageprovider -name $path;
|
||||
} -ArgumentList @($path)
|
||||
|
||||
$a= $job | Receive-Job -Wait
|
||||
$a.Name | should match "PSChained1Provider"
|
||||
}
|
||||
|
||||
It "Import a PowerShell package provider with -force, Expect succeed" {
|
||||
|
||||
$path = "$($UserModuleFolder)\PSChained1Provider.psm1"
|
||||
$path | should Exist
|
||||
|
||||
$newPath = "$($UserModuleFolder)\MyTest.psm1"
|
||||
Copy-Item -Path $path -Destination $newPath -Force
|
||||
|
||||
|
||||
$job=Start-Job -ScriptBlock {
|
||||
param($newPath) import-packageprovider -name $newPath -Force;
|
||||
} -ArgumentList @($newPath)
|
||||
|
||||
$a= $job | Receive-Job -Wait
|
||||
$a.Name | should match "PSChained1Provider"
|
||||
|
||||
$job=Start-Job -ScriptBlock {
|
||||
|
||||
param($newPath)
|
||||
|
||||
import-packageprovider -name $newPath -Force
|
||||
Set-Content -Path $newPath -Value "#test" -force
|
||||
import-packageprovider -name $newPath -Force
|
||||
|
||||
} -ArgumentList @($newPath)
|
||||
|
||||
|
||||
Receive-Job -Wait -Job $job -ErrorVariable theError 2>&1
|
||||
$theError.FullyQualifiedErrorId | should be "FailedToImportProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "Import 'OneGetTest' PowerShell package provider that has multiple versions, Expect succeed" {
|
||||
#check all version of OneGetTest is listed
|
||||
$x = get-packageprovider "OneGetTest" -ListAvailable
|
||||
|
||||
|
||||
$x | ?{ $_.Version.ToString() -eq "9.9.0.0" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.Version.ToString() -eq "3.5.0.0" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.Version.ToString() -eq "1.1.0.0" } | should not BeNullOrEmpty
|
||||
|
||||
#latest one is imported
|
||||
$y = powershell '(import-packageprovider -name "OneGetTest").Version.Tostring()'
|
||||
$y | should match "9.9.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Describe "import-packageprovider Error Cases" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "Expected error when importing wildcard chars 'OneGetTest*" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'import-packageprovider -name OneGetTest* -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "InvalidParameter,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when inputing a bad version format" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'import-packageprovider -name Gistprovider -RequiredVersion BOGUSVERSION -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "InvalidVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'import-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with file full path and version" {
|
||||
$Error.Clear()
|
||||
$msg = powershell {import-packageprovider -name "$($ProgramModulePath)\PSChained1Provider.psm1" -RequiredVersion 9.9.9 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId}
|
||||
$msg | should be "FullProviderFilePathVersionNotAllowed,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MinimumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'import-packageprovider -name PowerShellGet -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MaximumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'import-packageprovider -name PowerShellGet -RequiredVersion 1.0 -MaximumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with a MinimumVersion greater than MaximumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'import-packageprovider -name PowerShellGet -MaximumVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "MinimumVersionMustBeLessThanMaximumVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with MinimumVersion that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'Import-packageprovider -name OneGetTest -MinimumVersion 20.2 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with MaximumVersion that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'Import-packageprovider -name OneGetTest -MaximumVersion 0.2 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider that has name with wildcard and version" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'Import-packageprovider -name "OneGetTest*" -RequiredVersion 4.5 -force -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "MultipleNamesWithVersionNotAllowed,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Describe "Import-PackageProvider with OneGetTest that has 3 versions: 1.1, 3.5, and 9.9." -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "EXPECTED: success 'import OneGetTest -requiredVersion 3.5'" {
|
||||
powershell '(Import-packageprovider -name OneGetTest -requiredVersion 3.5 -WarningAction SilentlyContinue).Version.ToString()' | should match "3.5.0.0"
|
||||
|
||||
# test that if we call a function with error, powershell does not hang for the provider
|
||||
$warningMsg = powershell '(Import-packageprovider -name OneGetTest -requiredVersion 3.5) | Out-Null; Get-Package -ProviderName OneGetTest 3>&1'
|
||||
$result = $warningMsg[0]
|
||||
|
||||
if ($PSCulture -eq "en-US") {
|
||||
foreach($w in $warningMsg)
|
||||
{
|
||||
if($w -match 'WARNING: Cannot bind parameter')
|
||||
{
|
||||
$result = $w
|
||||
}
|
||||
|
||||
}
|
||||
$result.StartsWith('WARNING: Cannot bind parameter') | should be $true
|
||||
}
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'Import OneGetTest -requiredVersion 3.5 and then 9.9 -force'" {
|
||||
$a = powershell {(Import-packageprovider -name OneGetTest -RequiredVersion 3.5) > $null; (Import-packageprovider -name OneGetTest -requiredVersion 9.9 -force)}
|
||||
$a.Version.ToString()| should match "9.9.0.0"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'import OneGetTest with MinimumVersion and MaximumVersion'" {
|
||||
powershell '(Import-packageprovider -name OneGetTest -MinimumVersion 1.2 -MaximumVersion 5.0 -WarningAction SilentlyContinue).Version.ToString()' | should match "3.5.0.0"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'OneGetTest with MaximumVersion'" {
|
||||
powershell '(Import-packageprovider -name OneGetTest -MaximumVersion 3.5 -WarningAction SilentlyContinue).Version.ToString()' | should match "3.5.0.0"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'OneGetTest with MinimumVersion'" {
|
||||
powershell '(Import-packageprovider -name OneGetTest -MinimumVersion 2.2 -WarningAction SilentlyContinue).Version.ToString()' | should match "9.9.0.0"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'OneGetTest Find-Package with Progress'" {
|
||||
$ps = [PowerShell]::Create()
|
||||
$ps.AddScript("Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Find-Package -ProviderName OneGetTest")
|
||||
$ps.Invoke()
|
||||
|
||||
$ps.Streams.Progress.Count | Should be 29
|
||||
|
||||
$culture = (Get-Culture).Name
|
||||
|
||||
if ($culture -eq "en-us") {
|
||||
$ps.Streams.Progress[1].Activity | Should match "Starting some progress"
|
||||
$ps.Streams.Progress[1].StatusDescription | should match "Processing"
|
||||
$ps.Streams.Progress[1].CurrentOperation | should match "Starting"
|
||||
|
||||
$ps.Streams.Progress[5].Activity | should match "Updating"
|
||||
$ps.Streams.Progress[5].StatusDescription | should match "Finding packages"
|
||||
|
||||
$ps.Streams.Progress[6].Activity | should match "Updating Inner"
|
||||
$ps.Streams.Progress[6].StatusDescription | should match "Finding inner packages"
|
||||
|
||||
$ps.Streams.Progress[7].Activity | should match "Updating Inner"
|
||||
|
||||
}
|
||||
|
||||
$ps.Streams.Progress[1].ActivityId | Should Be 0
|
||||
$ps.Streams.Progress[1].ParentActivityId | should be -1
|
||||
$ps.Streams.Progress[1].SecondsRemaining | should match 10
|
||||
$ps.Streams.Progress[1].RecordType -eq [System.Management.Automation.ProgressRecordType]::Processing | should be true
|
||||
$ps.Streams.Progress[1].PercentComplete | should be 22
|
||||
|
||||
$ps.Streams.Progress[2].SecondsRemaining | should be 5
|
||||
|
||||
$ps.Streams.Progress[4].PercentComplete | should be 100
|
||||
$ps.Streams.Progress[4].RecordType -eq [System.Management.Automation.ProgressRecordType]::Completed | should be true
|
||||
|
||||
$ps.Streams.Progress[5].PercentComplete | should be 0
|
||||
|
||||
$ps.Streams.Progress[6].PercentComplete | should be 0
|
||||
|
||||
$ps.Streams.Progress[7].PercentComplete | should be 25
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'OneGetTest Find-Package returns correct TagId'" {
|
||||
$ps = [PowerShell]::Create()
|
||||
$ps.AddScript("Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Find-Package -ProviderName OneGetTest")
|
||||
$result = $ps.Invoke() | Select -First 1
|
||||
|
||||
$result.TagId | should match "MyVeryUniqueTagId"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'OneGetTest Get-Package returns correct package object using swidtag'" {
|
||||
$ps = [PowerShell]::Create()
|
||||
$null = $ps.AddScript("`$null = Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Get-Package -ProviderName OneGetTest")
|
||||
$result = $ps.Invoke()
|
||||
|
||||
$result.Count | should Be 2
|
||||
|
||||
($result | Select -Last 1).TagId | should match "jWhat-jWhere-jWho-jQuery"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'OneGetTest Get-Package returns correct progress message'" {
|
||||
$ps = [PowerShell]::Create()
|
||||
$null = $ps.AddScript("`$null = Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Get-Package -ProviderName OneGetTest")
|
||||
$result = $ps.Invoke()
|
||||
|
||||
$ps.Streams.Progress[1].PercentComplete | should be 0
|
||||
$ps.Streams.Progress[1].Activity | should match "Updating"
|
||||
$ps.Streams.Progress[1].ActivityId | should be 10
|
||||
|
||||
$ps.Streams.Progress[2].PercentComplete | should be 0
|
||||
$ps.Streams.Progress[2].Activity | should match "Updating Inner"
|
||||
$ps.Streams.Progress[2].ParentActivityId | should be 10
|
||||
|
||||
$ps.Streams.Progress[3].PercentComplete | should be 25
|
||||
$ps.Streams.Progress[3].Activity | should match "Updating Inner"
|
||||
$ps.Streams.Progress[3].ParentActivityId | should be 10
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Import-PackageProvider with OneGetTestProvider that has 2 versions: 4.5, 6.1" -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
# install onegettestprovider
|
||||
Install-PackageProvider -Name OneGetTestProvider -RequiredVersion 4.5.0.0 -Source $InternalGallery
|
||||
Install-PackageProvider -Name OneGetTestProvider -RequiredVersion 6.1.0.0 -Source $InternalGallery
|
||||
|
||||
It "EXPECTED: Get-PackageProvider -ListAvailable succeeds" {
|
||||
$providers = Get-PackageProvider -ListAvailable
|
||||
($providers | Where-Object {$_.Name -eq 'OneGetTest'}).Count | should match 3
|
||||
($providers | Where-Object {$_.Name -eq 'OneGetTestProvider'}).Count -ge 2 | should be $true
|
||||
}
|
||||
|
||||
It "EXPECTED: Get-PackageProvider -ListAvailable succeeds even after importing gist provider" {
|
||||
Install-PackageProvider GistProvider -Source $InternalGallery
|
||||
Import-PackageProvider Gist
|
||||
$providers = Get-PackageProvider -ListAvailable
|
||||
($providers | Where-Object {$_.Name -eq 'OneGetTest'}).Count | should match 3
|
||||
($providers | Where-Object {$_.Name -eq 'OneGetTestProvider'}).Count -ge 2 | should be $true
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'import OneGetTestProvider -requiredVersion 4.5'" {
|
||||
Import-PackageProvider -Name OneGetTestProvider -RequiredVersion 4.5 -Force
|
||||
(Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '4.5.0.0'
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'import OneGetTestProvider with MinimumVersion and MaximumVersion'" {
|
||||
Import-packageprovider -name OneGetTestProvider -MinimumVersion 4.6 -MaximumVersion 6.2 -Force
|
||||
(Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '6.1.0.0'
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'import OneGetTestProvider with MaximumVersion'" {
|
||||
Import-packageprovider -name OneGetTestProvider -MaximumVersion 4.6 -Force
|
||||
(Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '4.5.0.0'
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'OneGetTestProvider with MinimumVersion'" {
|
||||
Import-packageprovider -name OneGetTestProvider -MinimumVersion 6.0.5 -Force
|
||||
|
||||
(Get-PackageProvider OneGetTestProvider).Version -ge [version]'6.1.0.0' | should be $true
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'Import OneGetTestProvider -requiredVersion 4.5 and then 6.1 -force'" {
|
||||
Import-PackageProvider -Name OneGetTestProvider -RequiredVersion 4.5 -Force;
|
||||
Import-PackageProvider -Name OneGetTestProvider -RequiredVersion 6.1 -Force;
|
||||
(Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '6.1.0.0'
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'Import OneGetTestProvider -MinimumVersion 4.5 and then MaximumVersion 5.0 -force'" {
|
||||
Import-PackageProvider -Name OneGetTestProvider -MinimumVersion 4.5 -Force;
|
||||
(Get-PackageProvider OneGetTestProvider).Version -ge [version]'6.1.0.0' | should be $true
|
||||
Import-PackageProvider -Name OneGetTestProvider -MaximumVersion 5.0 -Force;
|
||||
(Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '4.5.0.0'
|
||||
}
|
||||
}
|
|
@ -0,0 +1,812 @@
|
|||
#
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# ------------------ PackageManagement Test -----------------------------------
|
||||
ipmo "$PSScriptRoot\utility.psm1"
|
||||
$InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/"
|
||||
$InternalGallery2 = "http://dtlgalleryint.cloudapp.net/api/v2/"
|
||||
$InternalSource = 'OneGetTestSource'
|
||||
$InternalSource2 = 'OneGetTestSource2'
|
||||
$ProviderFolder = "$env:ProgramFiles\PackageManagement\ProviderAssemblies"
|
||||
$destination = "$env:tmp\installpp"
|
||||
|
||||
#make sure the package repository exists
|
||||
$a=Get-PackageSource -ForceBootstrap| select Name, Location, ProviderName
|
||||
|
||||
$found = $false
|
||||
foreach ($item in $a)
|
||||
{
|
||||
#name contains "." foo.bar for example for the registered sources internally
|
||||
if($item.ProviderName -eq "PowerShellGet")
|
||||
{
|
||||
if (($item.Location -eq $InternalGallery) -or ($item.Location -eq $InternalGallery2)) {
|
||||
Unregister-PackageSource $item.Name -Provider "PowerShellGet" -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue
|
||||
Register-PackageSource -Name $InternalSource2 -Location $InternalGallery2 -ProviderName 'PowerShellGet' -ForceBootstrap -ErrorAction SilentlyContinue
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Actual Tests:
|
||||
|
||||
Describe "install-packageprovider" -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
BeforeEach {
|
||||
|
||||
$m= Get-InstalledModule -Name myalbum -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
if($m -and $m.InstalledLocation)
|
||||
{
|
||||
Remove-Item -Path $m.InstalledLocation -Recurse -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Verbose
|
||||
}
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
|
||||
It "install-packageprovider, Expect succeed" {
|
||||
#avoid popup for installing nuget-any.exe
|
||||
Find-PackageProvider -force
|
||||
$a = (install-PackageProvider -name gistprovider -force -source $InternalSource).name
|
||||
$a -contains "gistprovider" | should be $true "gistprovider"
|
||||
|
||||
# check for swidtag field
|
||||
$gist = (Get-PackageProvider gist -ListAvailable | Select -First 1)
|
||||
|
||||
$gist.Entities.Count | should be 2
|
||||
|
||||
$found = $false
|
||||
|
||||
foreach ($entity in $gist.Entities)
|
||||
{
|
||||
if ($entity.Name -match "Doug Finke" -and $entity.Role -match "author")
|
||||
{
|
||||
$found = $true
|
||||
}
|
||||
}
|
||||
|
||||
$found | should be $true
|
||||
|
||||
$gist.VersionScheme | should match "MultiPartNumeric"
|
||||
}
|
||||
|
||||
|
||||
It "install-packageprovider from bootstrap web site, Expect succeed" {
|
||||
$a = (Install-PackageProvider -Name nuget -RequiredVersion 2.8.5.127 -Force).name
|
||||
$a | should match "nuget"
|
||||
|
||||
# check for swidtag field
|
||||
$nugetBootstrapped = (Get-PackageProvider -Name nuget -ListAvailable | Where-Object {$_.Version.ToString() -eq "2.8.5.127"} | Select-Object -First 1)
|
||||
|
||||
$nugetBootstrapped.Links[0].HRef.ToString() | should match "https://oneget.org/nuget-anycpu-2.8.5.127.exe"
|
||||
$nugetBootstrapped.Links[0].Relationship | should match "installationmedia"
|
||||
}
|
||||
|
||||
It "find | install-packageprovider -name array, Expect succeed" {
|
||||
$names=@("gistprovider", "TSDProvider")
|
||||
|
||||
#
|
||||
$a = (find-PackageProvider -name $names -Source $InternalSource | Install-PackageProvider -force).name
|
||||
$a -contains "GistProvider" | should be $true
|
||||
$a -contains "TSDProvider" | should be $true
|
||||
}
|
||||
|
||||
It "find | install-packageprovider nuget should imported and installed, Expect succeed" {
|
||||
|
||||
$a = Find-PackageProvider -name NuGet -RequiredVersion 2.8.5.202 | install-PackageProvider -force
|
||||
$a.Name | Should match "NuGet"
|
||||
$a.Version | Should match "2.8.5.202"
|
||||
|
||||
}
|
||||
|
||||
It "find | install-packageprovider nuget should imported and installed, Expect succeed" {
|
||||
|
||||
$a = install-PackageProvider -name NuGet -force
|
||||
$a | ?{ $_.name -eq "NuGet" } | should not BeNullOrEmpty
|
||||
$a | ?{ $_.Version -gt "2.8.5.202" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "find | install-packageprovider myalbum should imported and installed, Expect succeed" {
|
||||
|
||||
$a = Install-PackageProvider -name MyAlbum -Source $InternalSource -force
|
||||
$a | ?{ $_.name -eq "MyAlbum" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "find | install-packageprovider myalbum should imported and installed, Expect succeed" {
|
||||
|
||||
$a = Find-PackageProvider -name MyAlbum -Source $InternalSource -RequiredVersion 0.1.2 | install-PackageProvider -force
|
||||
$a | ?{ $_.name -eq "MyAlbum" } | should not BeNullOrEmpty
|
||||
$a | ?{ $_.Version -eq "0.1.2" } | should not BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Describe "install-packageprovider with local source" -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
BeforeAll{
|
||||
if( test-path $destination ) {
|
||||
rmdir -recurse -force $destination -ea silentlycontinue
|
||||
}
|
||||
mkdir $destination -ea silentlycontinue
|
||||
|
||||
$nugetprovider = (install-PackageProvider -name nuget -force -RequiredVersion 2.8.5.201).name
|
||||
$nugetprovider -contains "nuget" | should be $true "nuget"
|
||||
|
||||
$nugetprovider = (install-PackageProvider -name nuget -force -RequiredVersion 2.8.5.202).name
|
||||
$nugetprovider -contains "nuget" | should be $true "nuget"
|
||||
|
||||
# setup the test folder
|
||||
|
||||
mkdir $destination\2.8.5.202 -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
mkdir $destination\2.8.5.201 -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
Get-ChildItem "$ProviderFolder\Nuget\2.8.5.202" -Recurse | Copy-Item -Destination $destination\2.8.5.202\Microsoft.PackageManagement.NuGetProvider.dll -Force -Verbose
|
||||
Get-ChildItem "$ProviderFolder\Nuget\2.8.5.201" -Recurse | Copy-Item -Destination $destination\2.8.5.201\Microsoft.PackageManagement.NuGetProvider.dll -Force -Verbose
|
||||
Get-ChildItem "$Env:ProgramFiles\WindowsPowerShell\Modules\Microsoft.PackageManagement.Test.dll" | Copy-Item -Destination $destination -Force -verbose
|
||||
|
||||
}
|
||||
|
||||
AfterAll{
|
||||
|
||||
if( test-path $destination ) {
|
||||
rmdir -recurse -force $destination -ea silentlycontinue
|
||||
}
|
||||
|
||||
$testprovider = "$ProviderFolder\Test Providers for OneGet"
|
||||
if( test-path $testprovider ) {
|
||||
rmdir -recurse -force $testprovider -ea silentlycontinue
|
||||
}
|
||||
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
|
||||
|
||||
|
||||
It "Find-packageprovider -source filefolder, Expect succeed" {
|
||||
|
||||
$a= (Find-PackageProvider -source $destination).Name
|
||||
|
||||
$a -like "nuget*" | should be $true
|
||||
$a -like "Test Providers for OneGet" | should be $true
|
||||
|
||||
}
|
||||
|
||||
It "Find-packageprovider -source filefolder -name, Expect the latest version returned" {
|
||||
|
||||
$a= Find-PackageProvider -source $destination -name nuget*
|
||||
|
||||
$a.Name -like "nuget*" | should match $true
|
||||
$a.Version | should match "2.8.5.202"
|
||||
}
|
||||
|
||||
It "Find-packageprovider -source filefolder -name -allversions, Expect All versions returned" {
|
||||
|
||||
$a= Find-PackageProvider -source $destination -name nuget* -AllVersions
|
||||
|
||||
# all versions returned
|
||||
$a | ?{$_.version -eq "2.8.5.202" } | should not BeNullOrEmpty
|
||||
$a | ?{$_.version -eq "2.8.5.201" } | should not BeNullOrEmpty
|
||||
|
||||
}
|
||||
|
||||
It "Find-packageprovider -source file, Expect succeed" {
|
||||
$a= (Find-PackageProvider -source "$destination\Microsoft.PackageManagement.Test.dll").Name
|
||||
|
||||
$a -like "nuget" | should not be $true
|
||||
$a -contains "Test Providers for OneGet" | should be $true
|
||||
|
||||
}
|
||||
|
||||
|
||||
It "Install-packageprovider -source file, Expect succeed" {
|
||||
|
||||
$a= (Install-PackageProvider -source "$destination\Microsoft.PackageManagement.Test.dll" -name "Test Providers for OneGet" -force).Name
|
||||
|
||||
$a -eq "Test Providers for OneGet" | should be $true
|
||||
|
||||
}
|
||||
|
||||
It "install-PackageProvider -source folder, Expect succeed" {
|
||||
|
||||
$a= (Install-PackageProvider -force -source $destination -name "Test Providers for OneGet")
|
||||
|
||||
|
||||
$a.Name -eq "Test Providers for OneGet" | should be $true
|
||||
|
||||
}
|
||||
|
||||
It "Find-packageprovider and install-PackageProvider, Expect succeed" {
|
||||
|
||||
$a= (find-PackageProvider -Name "Test Providers for OneGet" -Source $destination | Install-PackageProvider -force)
|
||||
|
||||
$a.Name -contains "Test Providers for OneGet" | should be $true
|
||||
|
||||
}
|
||||
|
||||
It "Find and Install PackageProvider with version, Expect succeed" {
|
||||
|
||||
$a= install-PackageProvider -Name nugetprovider -Source $destination -RequiredVersion 2.8.5.201 -verbose -force
|
||||
|
||||
$a.Name -like "nuget*" | should be $true
|
||||
$a.Version | should match "2.8.5.201"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Install-Save-Package with multiple sources" -Tags @('BVT', 'DRT'){
|
||||
# make sure packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
BeforeAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
install-PackageProvider -name nuget -force
|
||||
}
|
||||
AfterAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
|
||||
It "install-package with array of registered sources with a single provider, Expect succeed" {
|
||||
|
||||
#powershellget is the provider selected
|
||||
$x= install-package TSDProvider -force -Source @($InternalSource, $InternalSource2)
|
||||
|
||||
$x | ?{ $_.name -eq "TSDProvider" } | should not BeNullOrEmpty
|
||||
|
||||
$y= install-package TSDProvider -force -Source @($InternalGallery, $InternalGallery2) -ProviderName nuget
|
||||
|
||||
$y | ?{ $_.name -eq "TSDProvider" } | should not BeNullOrEmpty
|
||||
|
||||
}
|
||||
|
||||
It "install-package with array of sources, Expect succeed" {
|
||||
|
||||
$x= install-package jquery -force -Source @('foooobarrrr', 'https://www.nuget.org/api/v2') -ProviderName @('PowershellGet', 'NuGet')
|
||||
|
||||
$x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.Source -eq "https://www.nuget.org/api/v2" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "install-save-package matches with multiple providers with single source, Expect succeed" {
|
||||
|
||||
try
|
||||
{
|
||||
Register-PackageSource -Name foo -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
|
||||
Register-PackageSource -Name bar -Location $InternalGallery -ProviderName 'NuGet' -ErrorAction SilentlyContinue
|
||||
if (test-path "$destination") {
|
||||
rm $destination -force -Recurse
|
||||
}
|
||||
|
||||
|
||||
$x= install-package tsdprovider -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet')
|
||||
|
||||
$x | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.Source -eq "bar" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.Providername -eq "NuGet" } | should not BeNullOrEmpty
|
||||
|
||||
$y= save-package tsdprovider -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet') -path $destination
|
||||
|
||||
$y | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty
|
||||
$y | ?{ $_.Source -eq "bar" } | should not BeNullOrEmpty
|
||||
$y | ?{ $_.Providername -eq "NuGet" } | should not BeNullOrEmpty
|
||||
|
||||
(test-path "$destination\TSDProvider*") | should be $true
|
||||
if (test-path "$destination\TSDProvider*") {
|
||||
rm $destination\TSDProvider* -force -Recurse
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnRegister-PackageSource -Name foo -ErrorAction SilentlyContinue
|
||||
UnRegister-PackageSource -Name bar -ErrorAction SilentlyContinue
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
It "install-save-package does not match with any providers with single source, Expect fail" {
|
||||
|
||||
try
|
||||
{
|
||||
Register-PackageSource -Name foo -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
|
||||
Register-PackageSource -Name bar -Location $InternalGallery -ProviderName 'NuGet' -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
$Error.Clear()
|
||||
$x= install-package jquery -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet') -ErrorVariable theError -ErrorAction SilentlyContinue
|
||||
$theError.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage"
|
||||
|
||||
|
||||
$Error.Clear()
|
||||
$y= save-package jquery -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet') -path $destination -ErrorVariable theError -ErrorAction SilentlyContinue
|
||||
$theError.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage"
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnRegister-PackageSource -Name foo -ErrorAction SilentlyContinue
|
||||
UnRegister-PackageSource -Name bar -ErrorAction SilentlyContinue
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
It "install-save-package when the multiple providers find a package but no providers specified, Expect fail" {
|
||||
|
||||
try
|
||||
{
|
||||
Register-PackageSource -Name foo -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue
|
||||
Register-PackageSource -Name bar -Location $InternalGallery -ProviderName 'NuGet' -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
$Error.Clear()
|
||||
$x= install-package tsdprovider -force -Source @($InternalGallery) -ErrorVariable theError -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
$theError.FullyQualifiedErrorId | should be "DisambiguateForInstall,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage"
|
||||
|
||||
|
||||
$Error.Clear()
|
||||
$y= save-package tsdprovider -force -Source @($InternalGallery) -path $destination -ErrorVariable theError -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
$theError.FullyQualifiedErrorId | should be "DisambiguateForInstall,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage"
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnRegister-PackageSource -Name foo -ErrorAction SilentlyContinue
|
||||
UnRegister-PackageSource -Name bar -ErrorAction SilentlyContinue
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
It "install-save-package with multiple names, providers, Expect succeed" {
|
||||
|
||||
try {
|
||||
|
||||
Register-PackageSource -Name foobar -Location http://www.nuget.org/api/v2 -ProviderName 'NuGet' -ErrorAction SilentlyContinue
|
||||
|
||||
if (test-path "$destination") {
|
||||
rm $destination -force -Recurse
|
||||
}
|
||||
|
||||
|
||||
$x= install-package -name @('Bootstrap', 'jquery') -force -ProviderName @('NuGet', 'Chocolatey')
|
||||
|
||||
$x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.name -eq "Bootstrap" } | should not BeNullOrEmpty
|
||||
|
||||
|
||||
$y= save-package -name 'jquery' -force -ProviderName @('NuGet', 'Chocolatey') -path $destination
|
||||
|
||||
$x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty
|
||||
|
||||
|
||||
(test-path "$destination\jquery*") | should be $true
|
||||
if (test-path "$destination\jquery*") {
|
||||
rm $destination\jquery* -force -Recurse
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnRegister-PackageSource -Name foobar -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
It "install-save-package with multiple names, providers and sources, Expect succeed" {
|
||||
|
||||
|
||||
# Contoso and Contososerver can be found from $InternalGallery - No ambiguity.
|
||||
# Jquery can be found by the NuGet from both source locations provided.
|
||||
|
||||
|
||||
if (test-path "$destination") {
|
||||
rm $destination -force -Recurse
|
||||
}
|
||||
|
||||
|
||||
$x= install-package -name @('Contoso', 'jquery', 'ContosoServer') -force -Source @($InternalGallery, 'http://www.nuget.org/api/v2', 'https://www.nuget.org/api/v2') -ProviderName @('NuGet', 'Chocolatey')
|
||||
|
||||
$x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.name -eq "Contoso" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.name -eq "ContosoServer" } | should not BeNullOrEmpty
|
||||
|
||||
|
||||
$y= save-package -name @('Contoso', 'jquery', 'ContosoServer') -force -Source @($InternalGallery,'http://www.nuget.org/api/v2','https://www.nuget.org/api/v2') -ProviderName @('NuGet', 'Chocolatey') -path $destination
|
||||
|
||||
$x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.name -eq "Contoso" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.name -eq "ContosoServer" } | should not BeNullOrEmpty
|
||||
|
||||
(test-path "$destination\Contoso*") | should be $true
|
||||
if (test-path "$destination\Contoso*") {
|
||||
rm $destination\Contoso* -force -Recurse
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
It "save-package with array of registered sources, Expect succeed" {
|
||||
if (test-path "$destination") {
|
||||
rm $destination -force -Recurse
|
||||
}
|
||||
|
||||
$x= save-package TSDProvider -force -Source @($InternalSource, $InternalSource2) -path $destination -ProviderName @('PowershellGet', 'NuGet')
|
||||
|
||||
$x | ?{ $_.name -eq "TSDProvider" } | should not BeNullOrEmpty
|
||||
|
||||
(test-path "$destination\TSDProvider*") | should be $true
|
||||
if (test-path "$destination\TSDProvider*") {
|
||||
rm $destination\TSDProvider* -force -Recurse
|
||||
}
|
||||
}
|
||||
|
||||
It "save-package with array of sources, Expect succeed" {
|
||||
if (test-path "$destination") {
|
||||
rm $destination -force -Recurse
|
||||
}
|
||||
|
||||
$x= save-package jquery -force -Source @('fffffbbbbb', 'https://www.nuget.org/api/v2') -path $destination -ProviderName @('Nuget', 'Chocolatey')
|
||||
|
||||
$x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.Source -eq "https://www.nuget.org/api/v2" } | should not BeNullOrEmpty
|
||||
|
||||
(test-path "$destination\jquery*") | should be $true
|
||||
if (test-path "$destination\jquery*") {
|
||||
rm $destination\jquery* -force -Recurse
|
||||
}
|
||||
}
|
||||
}
|
||||
Describe "install-packageprovider with Whatif" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
#import-packagemanagement
|
||||
|
||||
BeforeEach{
|
||||
$tempFile = [System.IO.Path]::GetTempFileName()
|
||||
$whatif = "What if: Performing the operation";
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
if(Test-Path $tempFile)
|
||||
{
|
||||
Remove-Item $tempFile -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
AfterAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
|
||||
It "install-packageprovider -name nuget with whatif, Expect succeed" {
|
||||
|
||||
if($PSCulture -eq 'en-US'){
|
||||
|
||||
# Start Transcript
|
||||
Start-Transcript -Path $tempFile
|
||||
|
||||
install-PackageProvider -name nuget -force -warningaction:silentlycontinue -ErrorAction SilentlyContinue -whatif
|
||||
|
||||
# Stop Transcript and get content of transcript file
|
||||
Stop-Transcript
|
||||
$transcriptContent = Get-Content $tempFile
|
||||
|
||||
$transcriptContent | where { $_.Contains( $whatif ) } | should be $true
|
||||
|
||||
|
||||
Remove-Item $whatif -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
It "install-packageprovider -name gistprovider with whatif, Expect succeed" {
|
||||
|
||||
if($PSCulture -eq 'en-US'){
|
||||
# Start Transcript
|
||||
Start-Transcript -Path $tempFile
|
||||
|
||||
install-PackageProvider -name gistprovider -force -source $InternalGallery -warningaction:silentlycontinue -ErrorAction SilentlyContinue -whatif
|
||||
|
||||
# Stop Transcript and get content of transcript file
|
||||
Stop-Transcript
|
||||
$transcriptContent = Get-Content $tempFile
|
||||
|
||||
$transcriptContent | where { $_.Contains( $whatif ) } | should be $true
|
||||
|
||||
|
||||
Remove-Item $whatif -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "install-packageprovider with Scope" -Tags @('BVT', 'DRT'){
|
||||
BeforeAll {
|
||||
import-packagemanagement
|
||||
$userName = "smartguy"
|
||||
$password = "password%1"
|
||||
#net user $userName /delete | Out-Null
|
||||
net user $userName $password /add
|
||||
$secesurestring = ConvertTo-SecureString $password -AsPlainText -Force
|
||||
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $secesurestring
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
# Delete the user profile
|
||||
net user $userName /delete | Out-Null
|
||||
<#$userProfilePath = (Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -match $userName})
|
||||
|
||||
if($path -and (Test-Path $userProfilePath.LocalPath)) {
|
||||
Remove-Item $path -Force -Recurse -ErrorAction SilentlyContinue -verbose
|
||||
}#>
|
||||
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
|
||||
$m= Get-InstalledModule -Name tsdprovider -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
if($m -and $m.InstalledLocation)
|
||||
{
|
||||
Remove-Item -Path $m.InstalledLocation -Recurse -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Verbose
|
||||
}
|
||||
}
|
||||
It "install-packageprovider without scope in a non-admin console, expect fail" {
|
||||
|
||||
$Error.Clear()
|
||||
|
||||
$job=Start-Job -ScriptBlock { Install-PackageProvider -Name nuget -force -requiredVersion 2.8.5.127} -Credential $credential
|
||||
|
||||
Receive-Job -Wait -Job $job -ErrorVariable theError 2>&1
|
||||
$theError.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
It "install-packageprovider without scope in a non-admin console, expect fail" {
|
||||
|
||||
$Error.Clear()
|
||||
|
||||
$job=Start-Job -ScriptBlock { Install-PackageProvider -Name gistprovider -force } -Credential $credential
|
||||
|
||||
Receive-Job -Wait -Job $job -ErrorVariable theError 2>&1
|
||||
$theError.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
It "install-packageprovider with AllUsers scope in a non-admin console, expect fail" {
|
||||
$Error.Clear()
|
||||
|
||||
$job=Start-Job -ScriptBlock { Install-PackageProvider -Name gistprovider -force -scope AllUsers} -Credential $credential
|
||||
|
||||
Receive-Job -Wait -Job $job -ErrorVariable theError2 2>&1
|
||||
$theError2.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
|
||||
}
|
||||
|
||||
It "install-packageprovider CurrentUser scope in a non-admin console, expect succeed" {
|
||||
$Error.Clear()
|
||||
|
||||
$job=Start-Job -ScriptBlock {
|
||||
|
||||
$source="testsource"
|
||||
$x =Get-PackageSource -Name $source -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
||||
if ($x)
|
||||
{
|
||||
Write-Verbose "exist $source"
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Verbose "'$source' does not exist. Registering it"
|
||||
$InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/"
|
||||
Register-PackageSource -Name $source -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Install-PackageProvider -Name tsdprovider -force -scope CurrentUser -source $source
|
||||
} -Credential $credential
|
||||
|
||||
|
||||
$a= Receive-Job -Wait -Job $job
|
||||
$a | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "find and install-packageprovider without scope in a non-admin console, expect fail" {
|
||||
$Error.Clear()
|
||||
|
||||
$job=Start-Job -ScriptBlock { Find-PackageProvider -Name gistprovider | Install-PackageProvider -force} -Credential $credential
|
||||
|
||||
Receive-Job -Wait -Job $job -ErrorVariable theError3 2>&1
|
||||
$theError3.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
|
||||
}
|
||||
|
||||
It "find and install-packageprovider CurrentUser scope in a non-admin console, expect succeed" {
|
||||
$Error.Clear()
|
||||
|
||||
$job=Start-Job -ScriptBlock { Find-PackageProvider -Name tsdprovider | Install-PackageProvider -force -scope CurrentUser} -Credential $credential
|
||||
|
||||
$a= Receive-Job -Wait -Job $job
|
||||
$a | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
Describe "install-PackageProvider with Versions" -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
<# Nuget
|
||||
2.8.5.127
|
||||
2.8.5.122
|
||||
2.8.5.120
|
||||
2.8.5.101
|
||||
2.8.5.24#>
|
||||
|
||||
AfterAll{
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
It "EXPECTED: success 'install, import, and get nuget package provider'" {
|
||||
(install-packageprovider -name Nuget -requiredVersion 2.8.5.122 -force).Version.ToString() | should match "2.8.5.122"
|
||||
|
||||
$x = powershell {(import-packageprovider -name nuget -requiredVersion 2.8.5.122 -force > $null); get-packageprovider -name nuget}
|
||||
$x.Name | should match "Nuget"
|
||||
$x | ?{ $_.Version.ToString() -eq "2.8.5.122" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Install, import, and get a powershell package provider-required version" {
|
||||
$a = (install-PackageProvider -name gistprovider -force -requiredversion 1.5 -source $InternalSource)
|
||||
$a.Name -contains "gistprovider" | should be $true
|
||||
$a.Version -contains "1.5" | should be $true
|
||||
|
||||
$x = powershell {(import-packageprovider -name gist -requiredVersion 1.5 -force > $null); get-packageprovider -name gist -list}
|
||||
|
||||
$x | ?{ $_.name -eq "Gist" } | should not BeNullOrEmpty
|
||||
$x | ?{ $_.Version.ToString() -eq "1.5.0.0" } | should not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'install a provider with MinimumVersion and MaximumVersion'" {
|
||||
(install-packageprovider -name nuget -MinimumVersion 2.8.5.101 -MaximumVersion 2.8.5.123 -force).Version.ToString() | should match "2.8.5.122"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'install a provider with MaximumVersion'" {
|
||||
(install-packageprovider -name nuget -MaximumVersion 2.8.5.122 -force).Version.ToString() | should match "2.8.5.122"
|
||||
}
|
||||
|
||||
It "EXPECTED: success 'install a provider with MaximumVersion'" {
|
||||
$a = (install-packageprovider -name gistprovider -force -Source $InternalGallery).Version.ToString()
|
||||
$b = (install-packageprovider -name gistprovider -MinimumVersion 0.6 -force -Source $InternalSource).Version.ToString()
|
||||
|
||||
$a -eq $b | should be $true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Describe "Get-package with mulitiple providers" -Tags @('BVT', 'DRT'){
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
It "Get-package with multiple providers" {
|
||||
|
||||
$a = Install-package -Name TSDProvider -Source $InternalSource -ProviderName PowerShellGet -Force
|
||||
$b = install-package -name TSDProvider -Source $InternalGallery -ProviderName NuGet -Force
|
||||
|
||||
|
||||
$a.Name | should be "TSDProvider"
|
||||
$b.Name | should be "TSDProvider"
|
||||
|
||||
$c = Get-Package -name TSDProvider
|
||||
|
||||
$c.Count -ge 2 | should be $true
|
||||
$c | ?{ $_.ProviderName -eq "PowerShellGet" } | should not BeNullOrEmpty
|
||||
$c | ?{ $_.ProviderName -eq "NuGet" } | should not BeNullOrEmpty
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Describe "install-packageprovider Error Cases" -Tags @('BVT', 'DRT') {
|
||||
# make sure that packagemanagement is loaded
|
||||
import-packagemanagement
|
||||
|
||||
AfterAll {
|
||||
Unregister-PackageSource -Name OneGetTestSource -Verbose -ErrorAction SilentlyContinue
|
||||
Unregister-PackageSource -Name OneGetTestSource2 -Verbose -ErrorAction SilentlyContinue
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
}
|
||||
BeforeAll {
|
||||
#make sure we are using the latest Nuget provider
|
||||
Install-PackageProvider -name nuget -force
|
||||
Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue
|
||||
Register-PackageSource -Name $InternalSource2 -Location $InternalGallery2 -ProviderName 'PowerShellGet' -ForceBootstrap -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
It "install-packageprovider -name with wildcards, Expect error" {
|
||||
$Error.Clear()
|
||||
install-PackageProvider -name gist* -force -source $InternalGallery -warningaction:silentlycontinue -ErrorVariable wildcardError -ErrorAction SilentlyContinue
|
||||
$wildcardError.FullyQualifiedErrorId| should be "WildCardCharsAreNotSupported,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
It "install-packageprovider - EXPECTED: returns an error when multiples sources contain the same package provider" {
|
||||
$Error.Clear()
|
||||
$providers = find-packageprovider -name gistprovider
|
||||
$providers | ?{ $_.Source -match $InternalSource } | should not BeNullOrEmpty
|
||||
$providers | ?{ $_.Source -match $InternalSource2 } | should not BeNullOrEmpty
|
||||
|
||||
install-packageprovider -name gistprovider -source @($InternalSource, $InternalSource2) -ErrorVariable theError -force
|
||||
$theError.FullyQualifiedErrorId| should BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "install-package - EXPECTED: returns an error when multiples sources contain the same package provider" {
|
||||
$Error.Clear()
|
||||
$providers = find-package -name gistprovider
|
||||
$providers | ?{ $_.Source -match $InternalSource } | should not BeNullOrEmpty
|
||||
$providers | ?{ $_.Source -match $InternalSource2 } | should not BeNullOrEmpty
|
||||
|
||||
install-package -name gistprovider -force -Source @($InternalSource,$InternalSource2) -warningaction:silentlycontinue -ErrorVariable theError2 -ErrorAction SilentlyContinue
|
||||
$theError2.FullyQualifiedErrorId| should BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "save-package - EXPECTED: returns an error when multiples sources contain the same package provider" {
|
||||
$Error.Clear()
|
||||
$providers = find-package -name gistprovider
|
||||
$providers | ?{ $_.Source -match $InternalSource } | should not BeNullOrEmpty
|
||||
$providers | ?{ $_.Source -match $InternalSource2 } | should not BeNullOrEmpty
|
||||
|
||||
if(-not (test-path $destination) ) {
|
||||
mkdir $destination -ea silentlycontinue
|
||||
}
|
||||
|
||||
save-package -name gistprovider -Source @($InternalSource,$InternalSource2) -path $destination -warningaction:silentlycontinue -ErrorVariable theError2 -ErrorAction SilentlyContinue
|
||||
|
||||
$theError2.FullyQualifiedErrorId| should BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when inputing a bad version format" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'install-packageprovider -name nuget -RequiredVersion BOGUSVERSION -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "InvalidVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'install-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MinimumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'install-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MaximumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'install-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MaximumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with a MinimumVersion greater than MaximumVersion" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'install-packageprovider -name nuget -MaximumVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with MinimumVersion that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'install-packageprovider -name gistprovider -MinimumVersion 20.2 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
|
||||
It "EXPECTED: returns an error when asking for a provider with MaximumVersion that does not exist" {
|
||||
$Error.Clear()
|
||||
$msg = powershell 'install-packageprovider -name gistprovider -MaximumVersion 0.1 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId'
|
||||
$msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider"
|
||||
}
|
||||
}
|
1677
test/powershell/Modules/PackageManagement/Nuget.Tests.ps1
Normal file
1677
test/powershell/Modules/PackageManagement/Nuget.Tests.ps1
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue