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 1 commit
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
178 changes: 177 additions & 1 deletion Tests/GitHubRepositories.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,105 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent

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

Describe 'Getting repositories' {

Context -Name 'For getting a repository' -Fixture {
BeforeAll {
$repo = New-GitHubRepository -RepositoryName $defaultRepoName -Description $defaultRepoDesc -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)" -Verbose
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}

$newRepo = Get-GitHubRepository -RepositoryName $defaultRepoName
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
It 'Should get repository' {
$newRepo | Should Not BeNullOrEmpty
}

It 'Name is correct' {
$newRepo.name | Should be $defaultRepoName
}

It 'Description is correct' {
$newRepo.description | Should be $defaultRepoDesc
}
}

Context -Name 'For getting a from default/repository' -Fixture {
BeforeAll {
$originalOwnerName = Get-GitHubConfiguration -Name DefaultOwnerName
$originalRepositoryName = Get-GitHubConfiguration -Name DefaultRepositoryName
}
AfterAll {
Set-GitHubConfiguration -DefaultOwnerName $originalOwnerName
Set-GitHubConfiguration -DefaultRepositoryName $originalRepositoryName
}

$repo = Get-GitHubRepository
It 'Should get repository' {
$repo | Should Not BeNullOrEmpty
}

It 'Owner is correct' {
$repo.owner.login | Should be Get-GitHubConfiguration -Name DefaultOwnerName
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}

It 'Name is correct' {
$repo.name | Should be Get-GitHubConfiguration -Name DefaultRepositoryName
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Describe 'Creating repositories' {

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

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

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

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 $defaultRepoName -Description $defaultRepoDesc -AutoInit
}

$delete = Remove-GitHubRepository -RepositoryName $defaultRepoName -Verbose
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
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

Context -Name 'For renaming a repository' -Fixture {
BeforeEach -Scriptblock {
Expand All @@ -39,6 +137,84 @@ try
}
}
}

Describe 'Updating repositories' {

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

It 'Should have the new updated description' {
$updatedRepo = Update-GitHubRepository -RepositoryName $defaultRepoName -Description $modifiedRepoDesc
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
$updatedRepo.description | Should be $modifiedRepoDesc
}

It 'Should have the new updated homepage url' {
$updatedRepo = Update-GitHubRepository -RepositoryName $defaultRepoName -Homepage $defaultRepoHomePage
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
$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 $defaultRepoName -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)" -Verbose
}

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

It 'Should have no topics' {
$topic = Set-GitHubRepositoryTopic -RepositoryName $defaultRepoName -Clear
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
$updatedRepo.names | Should BeNullOrEmpty
}
}
}

Describe 'Get repository languages' {

Context -Name 'For getting repository languages' -Fixture {
BeforeAll {
$repo = New-GitHubRepositoryLanguage -RepositoryName $defaultRepoName -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)" -Verbose
}

$languages = Get-GitHubRepositoryLanguage -RepositoryName $defaultRepoName
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-GitHubRepositoryLanguage -RepositoryName $defaultRepoName -AutoInit
}
AfterAll {
Remove-GitHubRepository -Uri "$($repo.svn_url)" -Verbose
}

$tags = Get-GitHubRepositoryTag -RepositoryName $defaultRepoName
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
It 'Should be empty' {
$tags | Should BeNullOrEmpty
}
}
}
}
finally
{
Expand Down