Skip to content

Commit

Permalink
Merge branch 'WIP'
Browse files Browse the repository at this point in the history
  • Loading branch information
brywang-msft committed Dec 15, 2017
2 parents 375db6d + 099781f commit 206e6cb
Show file tree
Hide file tree
Showing 24 changed files with 591 additions and 279 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ os:
sudo: required
dist: trusty
osx_image: xcode7.3
env:
- api=v2
- api=v3

matrix:
allow_failures:
Expand All @@ -34,7 +37,7 @@ install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rvm use 2.2.1; gem uninstall bundler -v1.13.1; fi

script:
- ./tools/travis.sh
- ./tools/travis.sh $api



Expand Down
10 changes: 8 additions & 2 deletions Test/DSCTests/OneGetTestHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ configuration Sample_InstallPester
[string]$DestinationPath
)

Import-DscResource -Module PackageManagement -ModuleVersion 1.1.7.0
Import-DscResource -Module PackageManagement -ModuleVersion 1.2.0.0

Node "localhost"
{
Expand All @@ -65,7 +65,7 @@ configuration Sample_InstallPester
Ensure = "Present"
Name = "Mynuget"
ProviderName= "Nuget"
SourceLocation = "http://nuget.org/api/v2/"
SourceLocation = "$env:NUGET_API_URL"
InstallationPolicy ="Trusted"
}

Expand Down Expand Up @@ -167,10 +167,16 @@ function SetupPackageManagementTest
throw "Failed to find module base from GitCommitId $($PSVersionTable.GitCommitId)"
}
$script:PSModuleBase = $moduleBaseCandidate
$script:PSModuleBaseAlt = ((Resolve-Path -Path $moduleBaseCandidate\..\..\Modules).Path)
if (-not (Test-Path -Path $script:PSModuleBaseAlt)) {
$script:PSModuleBaseAlt = $script:PSModuleBase
}
Write-Verbose -Message "Path $script:PSModuleBase" -Verbose
Write-Verbose -Message "Alt Path $script:PSModuleBaseAlt" -Verbose
} else {
Write-Verbose -Message "Setting up test as Full CLR" -Verbose
$script:PSModuleBase = "$env:ProgramFiles\windowspowershell\modules"
$script:PSModuleBaseAlt = $script:PSModuleBase
}

UnRegisterAllSource
Expand Down
12 changes: 5 additions & 7 deletions Test/DSCTests/tests/PackageManagement.Set.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@


$CurrentDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path

. "$CurrentDirectory\..\OneGetTestHelper.ps1"
Import-Module "$CurrentDirectory\..\TestUtility.psm1" -Force

if (-not (IsAdmin))
{
throw "This test script requires to be run from an elevated PowerShell session. Launch an elevated PowerShell session and try again."
Expand All @@ -40,7 +38,7 @@ Describe -Name "PackageManagement Set-TargetResource Basic Test" -Tags "BVT" {

#Remove all left over files if exists
Remove-Item "$script:PSModuleBase\MyTestModule" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$script:PSModuleBase\MyTestModule" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$script:PSModuleBaseAlt\MyTestModule" -Recurse -Force -ErrorAction SilentlyContinue
}

AfterEach {
Expand All @@ -50,7 +48,7 @@ Describe -Name "PackageManagement Set-TargetResource Basic Test" -Tags "BVT" {
AfterAll {
# Remove all left over files if exists
Remove-Item "$script:PSModuleBase\MyTestModule" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$script:PSModuleBase\MyTestModule" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$script:PSModuleBaseAlt\MyTestModule" -Recurse -Force -ErrorAction SilentlyContinue

RestoreRepository $script:OriginalRepository
}
Expand All @@ -66,7 +64,7 @@ Describe -Name "PackageManagement Set-TargetResource Basic Test" -Tags "BVT" {
MSFT_PackageManagement\Set-TargetResource -name "MyTestModule" -Source $LocalRepository -Ensure Present -Verbose

# Validate the module is installed
Test-Path -Path "$script:PSModuleBase\MyTestModule\3.2.1" | should be $true
((Test-Path -Path "$script:PSModuleBase\MyTestModule\3.2.1") -or (Test-Path -Path "$script:PSModuleBaseAlt\MyTestModule\3.2.1")) | should be $true

# Uninstalling the module
MSFT_PackageManagement\Set-TargetResource -name "MyTestModule" -Source $LocalRepository -Ensure Absent -Verbose
Expand All @@ -75,7 +73,7 @@ Describe -Name "PackageManagement Set-TargetResource Basic Test" -Tags "BVT" {
$result = MSFT_PackageManagement\Test-TargetResource -name "MyTestModule" -Source $LocalRepository -Ensure Absent
$result| should be $true

Test-Path -Path "$script:PSModuleBase\MyTestModule\3.2.1" | should be $false
((Test-Path -Path "$script:PSModuleBase\MyTestModule\3.2.1") -or (Test-Path -Path "$script:PSModuleBaseAlt\MyTestModule\3.2.1")) | should be $false
}

It "Set, Test-TargetResource with Trusted Source, No respository Specified: Check Installed" {
Expand All @@ -87,7 +85,7 @@ Describe -Name "PackageManagement Set-TargetResource Basic Test" -Tags "BVT" {
MSFT_PackageManagement\Set-TargetResource -name "MyTestModule" -Ensure Present -Verbose

# Validate the module is installed
Test-Path -Path "$PSModuleBase\MyTestModule\3.2.1" | should be $true
((Test-Path -Path "$PSModuleBase\MyTestModule\3.2.1") -or (Test-Path -Path "$script:PSModuleBaseAlt\MyTestModule\3.2.1")) | should be $true

# Uninstalling the module
MSFT_PackageManagement\Set-TargetResource -name "MyTestModule" -Ensure Absent -Verbose
Expand Down
2 changes: 1 addition & 1 deletion Test/Examples/Sample_Install_Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ configuration Sample_Install_Package
)


Import-DscResource -Module PackageManagement -ModuleVersion 1.1.7.0
Import-DscResource -Module PackageManagement -ModuleVersion 1.2.0.0

Node $NodeName
{
Expand Down
4 changes: 2 additions & 2 deletions Test/Examples/Sample_Install_Package_Using_NuGet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ configuration Sample_Install_Package_Using_NuGet
[string]$InstallationPolicy
)

Import-DscResource -Module PackageManagement -ModuleVersion 1.1.7.0
Import-DscResource -Module PackageManagement -ModuleVersion 1.2.0.0

Node $NodeName
{
Expand All @@ -50,7 +50,7 @@ configuration Sample_Install_Package_Using_NuGet
Ensure = "Present"
Name = "MyNuget"
ProviderName= "Nuget"
SourceLocation = "http://nuget.org/api/v2/"
SourceLocation = "$env:NUGET_API_URL"
InstallationPolicy ="Trusted"
}

Expand Down
2 changes: 1 addition & 1 deletion Test/ModuleTests/tests/find-packageprovider.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Describe "find-packageprovider" -Tags "Feature" {
$a -contains "TSDProvider" | should be $true

$b = (Find-PackageProvider -name TSDP* -AllVersions).name
$b.Count -ge $a.Count | should be $true
$b.Count -ge $a.Count | should be $false
}


Expand Down
3 changes: 1 addition & 2 deletions Test/ModuleTests/tests/get-package.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#
# ------------------ PackageManagement Test ----------------------------------------------
$nuget = "nuget"
$source = "http://www.nuget.org/api/v2/"

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -57,7 +56,7 @@ Describe "Get-package with version parameter - valid scenarios" -Tags "Feature"
}

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)
($foundPackages = Find-Package -Name "adept.nugetrunner" -Provider $nuget -Source $env:NUGET_API_URL -AllVersions)

foreach ($package in $foundPackages)
{
Expand Down
2 changes: 1 addition & 1 deletion Test/ModuleTests/tests/legacy.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $IsLegacyTestRun = (Get-Variable -Name IsLegacyTestRun -ErrorAction Ignore) -and

Describe "Legacy tests" -Tags "Legacy" {
It "Can import on legacy PowerShell Core" -Skip:((-not $IsLegacyTestRun)) {
try { Import-Module PackageManagement -RequiredVersion 1.1.7.0 } catch {}
try { Import-Module PackageManagement -RequiredVersion 1.2.0.0 } catch {}
Get-Module PackageManagement | should not benullorempty
}
}
45 changes: 27 additions & 18 deletions Test/ModuleTests/tests/nuget.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ try {

$LinuxProgramFilesFolder="/usr/local/share/PackageManagement/NuGet/Packages"

$source = "http://www.nuget.org/api/v2/"
$sourceWithoutSlash = "http://www.nuget.org/api/v2"
$source = $env:NUGET_API_URL
$sourceWithoutSlash = $env:NUGET_API_URL_ALTERNATE
$fwlink = "http://go.microsoft.com/fwlink/?LinkID=623861&clcid=0x409"
$longName = "THISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERS";
$workingMaximumVersions = {"2.0", "2.5", "3.0"};
Expand Down Expand Up @@ -124,7 +124,7 @@ Describe "Event Test" -Tags "Feature" {

it "EXPECTED: install a package should raise event" -Skip:(-not $WindowsPowerShell) {

Install-Package EntityFramework -ProviderName nuget -requiredVersion 6.1.3 -Destination $TestDrive -source 'http://www.nuget.org/api/v2/' -force
Install-Package EntityFramework -ProviderName nuget -requiredVersion 6.1.3 -Destination $TestDrive -source $source -force

$retryCount= 5
while($retryCount -gt 0)
Expand Down Expand Up @@ -155,7 +155,7 @@ Describe "Event Test" -Tags "Feature" {
$event.Message | Should Match "Package=EntityFramework"
$event.Message | Should Match "Version=6.1.3"
$event.Message | Should Match "Provider=NuGet"
$event.Message | Should Match "Source=http://www.nuget.org/api/v2/"
$event.Message | Should Match "Source=$source"
#$event.Message | Should Match ([regex]::Escape("DestinationPath=$env:tmp"))

}
Expand Down Expand Up @@ -216,7 +216,7 @@ Describe "Event Test" -Tags "Feature" {

it "EXPECTED: uninstall a package should raise event" -Skip:(-not $WindowsPowerShell) {

Install-Package EntityFramework -ProviderName nuget -requiredVersion 6.1.3 -Destination $TestDrive -source 'http://www.nuget.org/api/v2/' -force
Install-Package EntityFramework -ProviderName nuget -requiredVersion 6.1.3 -Destination $TestDrive -source $source -force
UnInstall-Package EntityFramework -ProviderName nuget -Destination $TestDrive

$retryCount= 5
Expand Down Expand Up @@ -262,7 +262,7 @@ Describe "Event Test" -Tags "Feature" {

it "EXPECTED: save a package should raise event" -Skip:(-not $WindowsPowerShell) {

save-Package EntityFramework -ProviderName nuget -path $TestDrive -requiredVersion 6.1.3 -source 'http://www.nuget.org/api/v2/' -force
save-Package EntityFramework -ProviderName nuget -path $TestDrive -requiredVersion 6.1.3 -source $source -force

$retryCount= 5
while($retryCount -gt 0)
Expand Down Expand Up @@ -294,7 +294,7 @@ Describe "Event Test" -Tags "Feature" {
$event.Message | Should Match "Package=EntityFramework"
$event.Message | Should Match "Version=6.1.3"
$event.Message | Should Match "Provider=NuGet"
$event.Message | Should Match "Source=http://www.nuget.org/api/v2/"
$event.Message | Should Match "Source=$source"
# $event.Message | should Match ([regex]::Escape("DestinationPath=$env:tmp"))
}
else
Expand All @@ -321,8 +321,10 @@ Describe "Find-Package" -Tags @('Feature','SLOW'){
$zlib.Dependencies.Count | should be 1

$zlib.Meta.Attributes["packageSize"] | should match "7995520"

[long]$zlib.Meta.Attributes["versionDownloadCount"] -ge 7640 | should be $true
if ($env:NUGET_API_VERSION -eq 'v2')
{
[long]$zlib.Meta.Attributes["versionDownloadCount"] -ge 7640 | should be $true
}
$zlib.Meta.Attributes["requireLicenseAcceptance"] | should match "False"
$zlib.TagId | should match "grpc.dependencies.zlib#1.2.8.10"

Expand All @@ -340,16 +342,16 @@ Describe "Find-Package" -Tags @('Feature','SLOW'){
}

It "EXPECTED: Finds 100 packages should throw error" {
$packages = Find-Package -Provider $nuget -Source $source | Select -First 100
$packages = Get-Content "$PSScriptRoot\..\..\Packages_100.txt"

{ Find-Package -ProviderName $nuget -Source $source -Name $packages.Name -ErrorAction Stop } | should throw
{ Find-Package -ProviderName $nuget -Source $source -Name $packages -ErrorAction Stop } | should throw
}


It "EXPECTED: Finds 128 packages should throw error" {
$packages = Find-Package -Provider $nuget -Source $source | Select -First 127
$packages = Get-Content "$PSScriptRoot\..\..\Packages_128.txt"

{Find-Package -ProviderName $nuget -Source $source -Name $packages.Name -ErrorAction Stop} | should throw
{Find-Package -ProviderName $nuget -Source $source -Name $packages -ErrorAction Stop} | should throw
}

It "EXPECTED: Finds 'TestPackage' Package using fwlink" {
Expand Down Expand Up @@ -452,9 +454,16 @@ Describe "Find-Package" -Tags @('Feature','SLOW'){

# Uncomment this once publish the new version of nuget
$awssdk = Find-Package -Name "awssdk" -Provider $nuget -source $source -RequiredVersion 2.3.53
[long]$awssdk.Meta.Attributes["downloadCount"] -ge 1023357 | should be $true
$awssdk.Meta.Attributes["updated"] | should match "2015-12-15T17:46:22Z"
$awssdk.TagId | should match "AWSSDK#2.3.53.0"
# Currently v3 doesn't get this metadata
if ($env:NUGET_API_VERSION -eq 'v2')
{
[long]$awssdk.Meta.Attributes["downloadCount"] -ge 1023357 | should be $true
$awssdk.Meta.Attributes["updated"] | should match "2015-12-15T17:46:22Z"
$awssdk.TagId | should match "AWSSDK#2.3.53.0"
} else {
# For v3, the tag is going to be normalized
$awssdk.TagId | should match "AWSSDK#2.3.53"
}
}

It "EXPECTED: Finds A Combination Of Packages With Various Versions" {
Expand Down Expand Up @@ -820,7 +829,7 @@ Describe "save-package with Whatif" -Tags "Feature" {
}

It "install-package -name nuget with whatif where package has a dependencies, Expect succeed" {
{Save-Package -name zlib -source https://www.nuget.org/api/v2/ `
{Save-Package -name zlib -source $source `
-ProviderName NuGet -Path $tempDir -whatif} | should not throw
}
}
Expand Down Expand Up @@ -867,7 +876,7 @@ Describe "install-package with Whatif" -Tags "Feature" {
}

It "install-package -name nuget with whatif where package has a dependencies, Expect succeed" {
{install-Package -name grpc.dependencies.zlib -source https://www.nuget.org/api/v2/ `
{install-Package -name grpc.dependencies.zlib -source $source `
-ProviderName NuGet -destination $installationPath -whatif} | should not throw
}
}
Expand Down
Loading

0 comments on commit 206e6cb

Please sign in to comment.