Skip to content

Commit 3e69389

Browse files
committed
move warning to package provider layer
1 parent 6562e28 commit 3e69389

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

Tests/Pester.PSRepository.Tests.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,23 @@ Describe 'Managing repositories' -Tag BVT {
247247
}
248248

249249
It "Should let you register an unreachable repository but produce a warning" {
250-
Register-PSRepository -Name NewRepo -SourceLocation "https://nowhere.com/api/v2" -WarningVariable warning -WarningAction SilentlyContinue
250+
# microsoft.com exists but doesn't host a nuget repo
251+
Register-PSRepository -Name NewRepo -SourceLocation "https://microsoft.com/api/v2" -WarningVariable warning -WarningAction SilentlyContinue
251252
$warning | Should BeLike "*Unable to reach URL*"
252253
}
253254

255+
It "Should let you change a repo to an unreachable location but produce a warning" {
256+
Register-PSRepository -Name NewRepo -SourceLocation "https://www.microsoft.com/api/v2"-WarningAction SilentlyContinue
257+
Set-PSRepository -Name NewRepo -SourceLocation "https://docs.microsoft.com/api/v2" -WarningVariable warning -WarningAction SilentlyContinue
258+
$warning | Should BeLike "*Unable to reach URL 'https://docs*"
259+
}
260+
261+
It "Should let you add a package source but produce a warning" {
262+
Register-PackageSource NewRepo -Location https://microsoft.com/api/v2 -ProviderName powershellget -WarningVariable warning -WarningAction SilentlyContinue
263+
$warning | Should BeLike "*Unable to reach URL*"
264+
}
265+
266+
254267
It "Should not let you register 2 repositories which differ only by /" {
255268
Register-PSRepository -Name NewRepo -SourceLocation "https://nowhere.com/api/v2" -WarningAction SilentlyContinue
256269
{ Register-PSRepository -Name NewRepoSlash -SourceLocation "https://nowhere.com/api/v2/" -WarningAction SilentlyContinue } | Should -Throw

src/PowerShellGet/PSGet.Resource.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ConvertFrom-StringData @'
9999
FailedToPublish=Failed to publish module '{0}': '{1}'.
100100
PublishedSuccessfully=Successfully published module '{0}' to the module publish location '{1}'. Please allow few minutes for '{2}' to show up in the search results.
101101
InvalidWebUri=The specified Uri '{0}' for parameter '{1}' is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.
102-
WarnUnableToReachWebUri=Unable to reach URL at '{0}' for parameter '{1}'. Please check that the URL is correct.
102+
WarnUnableToReachWebUri=Unable to reach URL '{0}'. Please check that the URL is correct.
103103
RepositoryAlreadyRegistered=The repository could not be registered because there exists a registered repository with Name '{0}' and SourceLocation '{1}'. To register another repository with Name '{2}', please unregister the existing repository using the Unregister-PSRepository cmdlet.
104104
RepositoryToBeUnregisteredNotFound=The repository '{0}' was not removed because no repository was found with that name. Please run Get-PSRepository and ensure that a repository of that name is present.
105105
RepositoryCannotBeUnregistered=The specified repository '{0}' cannot be unregistered.

src/PowerShellGet/private/functions/Resolve-Location.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ function Resolve-Location
7373
else
7474
{
7575
# We couldn't reach the repo. Register it anyway but warn the user if we're able
76+
# We'd like to include the parameter name here, but Register-PSRepository calls Add-PackageSource,
77+
# and both use different param names, so the parameter name becomes confusing
7678
if($CallerPSCmdlet -and -not $SkipLocationWarning) {
77-
$message = $LocalizedData.WarnUnableToReachWebUri -f ($Location, $LocationParameterName)
79+
$message = $LocalizedData.WarnUnableToReachWebUri -f ($Location)
7880
Write-Warning $message
7981
}
8082
return $Location

src/PowerShellGet/public/providerfunctions/Add-PackageSource.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ function Add-PackageSource
266266
-Credential $Credential `
267267
-Proxy $Proxy `
268268
-ProxyCredential $ProxyCredential `
269-
-CallerPSCmdlet $PSCmdlet `
270-
-SkipLocationWarning # otherwise we get duplicate warnings for unreachable repos
269+
-CallerPSCmdlet $PSCmdlet
271270
}
272271

273272
if(-not (Microsoft.PowerShell.Management\Test-Path -Path $Location) -and

src/PowerShellGet/public/psgetfunctions/Register-PSRepository.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ function Register-PSRepository
149149
-Credential $Credential `
150150
-Proxy $Proxy `
151151
-ProxyCredential $ProxyCredential `
152-
-CallerPSCmdlet $PSCmdlet
153-
152+
-CallerPSCmdlet $PSCmdlet `
153+
-SkipLocationWarning
154+
154155
$providerName = $null
155156

156157
if($PackageManagementProvider)

0 commit comments

Comments
 (0)