Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alerickson committed Dec 19, 2024
1 parent fe270a1 commit a99b2b2
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/CredentialProvider.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force

Describe 'Test Azure Artifacts Credential Provider' -tags 'CI' {

BeforeAll{
$TestModuleName = "PackageManagement"
$ADORepoName = "ADORepository"
$ADORepoUri = "https://pkgs.dev.azure.com/mscodehub/PowerShellCore/_packaging/PowerShellCore_PublicPackages/nuget/v2"
$LocalRepoName = "LocalRepository"
$LocalRepoUri = Join-Path -Path $TestDrive -ChildPath "testdir"
$null = New-Item $LocalRepoUri -ItemType Directory -Force

Get-NewPSResourceRepositoryFile
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -Trusted
}

AfterAll {
Uninstall-PSResource $TestModuleName -SkipDependencyCheck -ErrorAction SilentlyContinue

Get-RevertPSResourceRepositoryFile
}

It "Find resource given specific Name and Repository" {
$res = Find-PSResource -Name $TestModuleName -Repository $ADORepoName
$res.Name | Should -Be $TestModuleName
}

It "Install resource given specific Name and Repository" {
Install-PSResource -Name $TestModuleName -Repository $ADORepoName

Get-InstalledPSResource -Name $TestModuleName | Should -Not -BeNullOrEmpty
}

It "Register repository with local path (CredentialProvider should be set to 'None')" {
Register-PSResourceRepository -Name $LocalRepoName -Uri $LocalRepoUri -Force
$repo = Get-PSResourceRepository -Name $LocalRepoName
$repo.CredentialProvider | Should -Be "None"
}

It "Set CredentialProvider for local path repository" {
Register-PSResourceRepository -Name $LocalRepoName -Uri $LocalRepoUri -Trusted -Force
$repo = Get-PSResourceRepository -Name $LocalRepoName
$repo.CredentialProvider | Should -Be "None"

Set-PSResourceRepository -Name $LocalRepoName -CredentialProvider AzArtifacts
$repo2 = Get-PSResourceRepository -Name $LocalRepoName
$repo2.CredentialProvider | Should -Be "AzArtifacts"
}

It "Register repository with ADO Uri (CredentialProvider should be set to 'AzArtifacts')" {
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -Force
$repo = Get-PSResourceRepository -Name $ADORepoName
$repo.CredentialProvider | Should -Be "AzArtifacts"
}

It "Set CredentialProvider for ADO repository" {
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -Trusted -Force
$repo = Get-PSResourceRepository -Name $ADORepoName
$repo.CredentialProvider | Should -Be "AzArtifacts"

Set-PSResourceRepository -Name $ADORepoName -CredentialProvider None
$repo2 = Get-PSResourceRepository -Name $ADORepoName
$repo2.CredentialProvider | Should -Be "None"
}

It "Register repository with ADO Uri (CredentialProvider should be set to 'AzArtifacts')" {
Register-PSResourceRepository -Name $ADORepoName -Uri $ADORepoUri -CredentialProvider None -Force
$repo = Get-PSResourceRepository -Name $ADORepoName
$repo.CredentialProvider | Should -Be "None"
}
}

0 comments on commit a99b2b2

Please sign in to comment.