Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to GitHubRepositories.tests.ps1 #176

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 198 additions & 2 deletions Tests/GitHubRepositories.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent

try
{
# Define Script-scoped, readonly, hidden variables.
@{
defaultRepoDesc = "This is a description."
defaultRepoHomePage = "https://www.microsoft.com/"
defaultRepoTopic = "microsoft"
}.GetEnumerator() | ForEach-Object {
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
}

Describe 'Getting repositories' {
Context 'For authenticated user' {
BeforeAll -Scriptblock {
Expand Down Expand Up @@ -68,7 +77,7 @@ try

$repos = Get-GitHubRepository -OrganizationName $script:organizationName -Type All
It "Should have results for the organization" {
$repo.name | Should BeIn $repos.name
$repo.Name | Should BeIn $repos.Name
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}

AfterAll -ScriptBlock {
Expand Down Expand Up @@ -128,7 +137,7 @@ try
}

It "Should have the expected new repository name - by Elements" {
$renamedRepo = Rename-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -NewName $newRepoName -Confirm:$false
$renamedRepo = Rename-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name -NewName $newRepoName -Confirm:$false
$renamedRepo.Name | Should be $newRepoName
}
## cleanup temp testing repository
Expand All @@ -138,6 +147,193 @@ try
}
}
}

Describe 'Creating repositories' {

Context -Name 'For creating a repository' -Fixture {
BeforeAll {
$repoName = ([Guid]::NewGuid().Guid) + "_name"
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
$repo = New-GitHubRepository -RepositoryName $repoName -Description $defaultRepoDesc -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)"
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}

It 'Should get repository' {
$repo | Should Not BeNullOrEmpty
}

It 'Name is correct' {
$repo.Name | Should be $repoName
}

It 'Description is correct' {
$repo.Description | Should be $defaultRepoDesc
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Describe 'Deleting repositories' {

Context -Name 'For deleting a repository' -Fixture {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Description $defaultRepoDesc -AutoInit
}

$delete = Remove-GitHubRepository -RepositoryName $repo.Name
It 'Should get no content' {
$repo | Should BeNullOrEmpty
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Describe 'Renaming repositories' {
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved

AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url
}
}

Context 'For public repos' {
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
# Skipping these tests for now, as it would run for a _very_ long time.
# No obviously good way to verify this.
}

Context 'For a specific repo' {
BeforeAll -Scriptblock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit

# Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments
$repo = $repo
}

$returned = Get-GitHubRepository -Uri $repo.svn_url
It "Should be a single result using Uri ParameterSet" {
$returned | Should -BeOfType PSCustomObject
}

$returned = Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name
It "Should be a single result using Elements ParameterSet" {
$returned | Should -BeOfType PSCustomObject
}

It 'Should not permit additional parameters' {
{ Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name -Type All } | Should Throw
}

It 'Should require both OwnerName and RepositoryName' {
{ Get-GitHubRepository -RepositoryName $repo.Name } | Should Throw
{ Get-GitHubRepository -Uri "https://github.com/$script:ownerName" } | Should Throw
}

AfterAll -ScriptBlock {
Remove-GitHubRepository -Uri $repo.svn_url
}
}
}

Describe 'Modifying repositories' {
Context -Name 'For renaming a repository' -Fixture {
BeforeEach -Scriptblock {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
$suffixToAddToRepo = "_renamed"
$newRepoName = "$($repo.Name)$suffixToAddToRepo"
}
It "Should have the expected new repository name - by URI" {
$renamedRepo = $repo | Rename-GitHubRepository -NewName $newRepoName -Confirm:$false
$renamedRepo.Name | Should be $newRepoName
}

It "Should have the expected new repository name - by Elements" {
$renamedRepo = Rename-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name -NewName $newRepoName -Confirm:$false
$renamedRepo.Name | Should be $newRepoName
}
## cleanup temp testing repository
AfterEach -Scriptblock {
## variables from BeforeEach scriptblock are accessible here, but not variables from It scriptblocks, so need to make URI (instead of being able to use $renamedRepo variable from It scriptblock)
Remove-GitHubRepository -Uri "$($repo.svn_url)$suffixToAddToRepo"
}
}
}

Describe 'Updating repositories' {

Context -Name 'For creating a repository' -Fixture {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Description $defaultRepoDesc -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)"
}

It 'Should have the new updated description' {
$modifiedRepoDesc = $defaultRepoDesc + "_modified"
$updatedRepo = Update-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name -Description $modifiedRepoDesc
$updatedRepo.description | Should be $modifiedRepoDesc
}

It 'Should have the new updated homepage url' {
$updatedRepo = Update-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.Name -Homepage $defaultRepoHomePage
$repo.homepage | Should be $defaultRepoHomePage
}
}
}

Describe 'Get/set repository topic' {

Context -Name 'For creating and getting a repository topic' -Fixture {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)"
}

It 'Should have the expected topic' {
$topic = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.Name -Name $defaultRepoTopic
$updatedRepo.names[0] | Should be $defaultRepoTopic
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}

It 'Should have no topics' {
$topic = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.Name -Clear
$updatedRepo.names | Should BeNullOrEmpty
}
}
}

Describe 'Get repository languages' {

Context -Name 'For getting repository languages' -Fixture {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)"
}

$languages = Get-GitHubRepositoryLanguage -OwnerName $repo.owner.login -RepositoryName $repo.Name
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
It 'Should be empty' {
$languages | Should BeNullOrEmpty
}
}
}

Describe 'Get repository tags' {

Context -Name 'For getting repository tags' -Fixture {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)"
}

$tags = Get-GitHubRepositoryTag -OwnerName $repo.owner.login -RepositoryName $repo.Name
It 'Should be empty' {
$tags | Should BeNullOrEmpty
}
}
}
}
finally
{
Expand Down