13
13
#
14
14
# ------------------ PackageManagement Test -----------------------------------
15
15
16
- $gallery = " https://www.powershellgallery.com/api/v2"
17
- $source = ' OneGetTestSource'
18
-
19
16
Describe " PackageManagement Acceptance Test" - Tags " Feature" {
20
17
21
- BeforeAll{
22
- Register-PackageSource - Name Nugettest - provider NuGet - Location https:// www.nuget.org/ api/ v2 - Force
18
+ BeforeAll {
19
+ # the package name for testing
20
+ $packageName = " PowerShell.TestPackage"
21
+
22
+ # register the asset directory
23
+ $localSourceName = [Guid ]::NewGuid().ToString(" n" )
24
+ $localSourceLocation = Join-Path $PSScriptRoot assets
25
+ Register-PackageSource - Name $localSourceName - provider NuGet - Location $localSourceLocation - Force - Trusted
26
+
27
+ # register the gallery location
28
+ $galleryLocation = " https://www.powershellgallery.com/api/v2"
29
+ $gallerySourceName = [Guid ]::newGuid().ToString(" n" )
30
+ Register-PackageSource - Name $gallerySourceName - Location $galleryLocation - ProviderName ' PowerShellGet' - Trusted - ErrorAction SilentlyContinue
31
+
32
+ $SavedProgressPreference = $ProgressPreference
33
+ $ProgressPreference = " SilentlyContinue"
34
+ }
23
35
24
- $packageSource = Get-PackageSource - Location $gallery - ErrorAction SilentlyContinue
25
- if ($packageSource ) {
26
- $source = $packageSource.Name
27
- Set-PackageSource - Name $source - Trusted
28
- } else {
29
- Register-PackageSource - Name $source - Location $gallery - ProviderName ' PowerShellGet' - Trusted - ErrorAction SilentlyContinue
36
+ AfterAll {
37
+ $ProgressPreference = $SavedProgressPreference
38
+ Unregister-PackageSource - Source $localSourceName - ErrorAction Ignore
39
+ Unregister-PackageSource - Name $gallerySourceName - ErrorAction Ignore
40
+ Uninstall-Module NanoServerPackage - ErrorAction Ignore - WarningAction SilentlyContinue
30
41
}
31
42
32
- $SavedProgressPreference = $ProgressPreference
33
- $ProgressPreference = " SilentlyContinue"
34
- }
35
- AfterAll {
36
- $ProgressPreference = $SavedProgressPreference
37
- }
38
43
It " get-packageprovider" {
39
-
40
44
$gpp = Get-PackageProvider
41
-
42
45
$gpp.Name | Should - Contain ' NuGet'
43
-
44
46
$gpp.Name | Should - Contain ' PowerShellGet'
45
47
}
46
48
@@ -50,32 +52,40 @@ Describe "PackageManagement Acceptance Test" -Tags "Feature" {
50
52
}
51
53
52
54
It " install-packageprovider, Expect succeed" {
53
- $ipp = (Install-PackageProvider - Name NanoServerPackage - Force - Source $source - Scope CurrentUser).name
55
+ Set-ItResult - Pending - Because " local test package provider not installable"
56
+ $ippArgs = @ {
57
+ Name = " NanoServerPackage"
58
+ Force = $true
59
+ Source = $galleryLocation
60
+ Scope = " CurrentUser"
61
+ WarningAction = " SilentlyContinue"
62
+ }
63
+ $ipp = (Install-PackageProvider @ippArgs ).name
54
64
$ipp | Should - Contain " NanoServerPackage"
55
65
}
56
66
57
67
It " Find-package" {
58
- $f = Find-Package - ProviderName NuGet - Name jquery - Source Nugettest
59
- $f.Name | Should - Contain " jquery "
68
+ $f = Find-Package - ProviderName NuGet - Name $packageName - Source $localSourceName
69
+ $f.Name | Should - Contain " $packageName "
60
70
}
61
71
62
72
It " Install-package" {
63
- $i = Install-Package - ProviderName NuGet - Name jquery - Force - Source Nugettest - Scope CurrentUser
64
- $i.Name | Should - Contain " jquery "
73
+ $i = Install-Package - ProviderName NuGet - Name $packageName - Force - Source $localSourceName - Scope CurrentUser
74
+ $i.Name | Should - Contain " $packageName "
65
75
}
66
76
67
77
It " Get-package" {
68
- $g = Get-Package - ProviderName NuGet - Name jquery
69
- $g.Name | Should - Contain " jquery "
78
+ $g = Get-Package - ProviderName NuGet - Name $packageName
79
+ $g.Name | Should - Contain " $packageName "
70
80
}
71
81
72
82
It " save-package" {
73
- $s = Save-Package - ProviderName NuGet - Name jquery - Path $TestDrive - Force - Source Nugettest
74
- $s.Name | Should - Contain " jquery "
83
+ $s = Save-Package - ProviderName NuGet - Name $packageName - Path $TestDrive - Force - Source $localSourceName
84
+ $s.Name | Should - Contain " $packageName "
75
85
}
76
86
77
87
It " uninstall-package" {
78
- $u = Uninstall-Package - ProviderName NuGet - Name jquery
79
- $u.Name | Should - Contain " jquery "
88
+ $u = Uninstall-Package - ProviderName NuGet - Name $packageName
89
+ $u.Name | Should - Contain " $packageName "
80
90
}
81
91
}
0 commit comments