Skip to content

Commit a99b2b2

Browse files
committed
Add tests
1 parent fe270a1 commit a99b2b2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/CredentialProvider.Tests.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force
5+
6+
Describe 'Test Azure Artifacts Credential Provider' -tags 'CI' {
7+
8+
BeforeAll{
9+
$TestModuleName = "PackageManagement"
10+
$ADORepoName = "ADORepository"
11+
$ADORepoUri = "https://pkgs.dev.azure.com/mscodehub/PowerShellCore/_packaging/PowerShellCore_PublicPackages/nuget/v2"
12+
$LocalRepoName = "LocalRepository"
13+
$LocalRepoUri = Join-Path -Path $TestDrive -ChildPath "testdir"
14+
$null = New-Item $LocalRepoUri -ItemType Directory -Force
15+
16+
Get-NewPSResourceRepositoryFile
17+
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -Trusted
18+
}
19+
20+
AfterAll {
21+
Uninstall-PSResource $TestModuleName -SkipDependencyCheck -ErrorAction SilentlyContinue
22+
23+
Get-RevertPSResourceRepositoryFile
24+
}
25+
26+
It "Find resource given specific Name and Repository" {
27+
$res = Find-PSResource -Name $TestModuleName -Repository $ADORepoName
28+
$res.Name | Should -Be $TestModuleName
29+
}
30+
31+
It "Install resource given specific Name and Repository" {
32+
Install-PSResource -Name $TestModuleName -Repository $ADORepoName
33+
34+
Get-InstalledPSResource -Name $TestModuleName | Should -Not -BeNullOrEmpty
35+
}
36+
37+
It "Register repository with local path (CredentialProvider should be set to 'None')" {
38+
Register-PSResourceRepository -Name $LocalRepoName -Uri $LocalRepoUri -Force
39+
$repo = Get-PSResourceRepository -Name $LocalRepoName
40+
$repo.CredentialProvider | Should -Be "None"
41+
}
42+
43+
It "Set CredentialProvider for local path repository" {
44+
Register-PSResourceRepository -Name $LocalRepoName -Uri $LocalRepoUri -Trusted -Force
45+
$repo = Get-PSResourceRepository -Name $LocalRepoName
46+
$repo.CredentialProvider | Should -Be "None"
47+
48+
Set-PSResourceRepository -Name $LocalRepoName -CredentialProvider AzArtifacts
49+
$repo2 = Get-PSResourceRepository -Name $LocalRepoName
50+
$repo2.CredentialProvider | Should -Be "AzArtifacts"
51+
}
52+
53+
It "Register repository with ADO Uri (CredentialProvider should be set to 'AzArtifacts')" {
54+
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -Force
55+
$repo = Get-PSResourceRepository -Name $ADORepoName
56+
$repo.CredentialProvider | Should -Be "AzArtifacts"
57+
}
58+
59+
It "Set CredentialProvider for ADO repository" {
60+
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -Trusted -Force
61+
$repo = Get-PSResourceRepository -Name $ADORepoName
62+
$repo.CredentialProvider | Should -Be "AzArtifacts"
63+
64+
Set-PSResourceRepository -Name $ADORepoName -CredentialProvider None
65+
$repo2 = Get-PSResourceRepository -Name $ADORepoName
66+
$repo2.CredentialProvider | Should -Be "None"
67+
}
68+
69+
It "Register repository with ADO Uri (CredentialProvider should be set to 'AzArtifacts')" {
70+
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -CredentialProvider None -Force
71+
$repo = Get-PSResourceRepository -Name $ADORepoName
72+
$repo.CredentialProvider | Should -Be "None"
73+
}
74+
}

0 commit comments

Comments
 (0)