From f31d79133df1310fac1f14643eea4cdb4972a26a Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Tue, 30 Jun 2020 12:58:04 -0700 Subject: [PATCH] Fix pipeline support and testing for New-GitHubRepositoryFromTemplate (#259) Added in #221, `New-GitHubRepositoryFromTemplate was not capturing the passed-in value for the RepositoryName if provided via a Uri parameter. There was a pipeline test in place, however it missed this fact because it was only testing the pipeline input scenario using `-WhatIf`, and the error was only found when calling the actual REST API and GitHub noticed that the `RepositoryName` was missing from the URI. --- GitHubRepositories.ps1 | 1 + Tests/GitHubRepositories.tests.ps1 | 38 +++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 8bc58389..847e82b5 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -364,6 +364,7 @@ filter New-GitHubRepositoryFromTemplate $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName + $RepositoryName = $elements.repositoryName $telemetryProperties = @{ RepositoryName = (Get-PiiSafeString -PlainText $RepositoryName) diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 9e7a0944..6fbcd27a 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -321,16 +321,48 @@ try } $repo = New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms + Start-Sleep -Seconds 1 # To work around a delay that GitHub may have with generating the repo } - It 'Should support pipeline input for the uri parameter' { + It 'Should have the expected type and addititional properties' { + $repo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' + $repo.name | Should -Be $repoName + $repo.private | Should -BeFalse + $repo.owner.login | Should -Be $script:ownerName + $repo.description | Should -Be $newRepoDesc + $repo.is_template | Should -BeFalse + $repo.RepositoryId | Should -Be $repo.id + $repo.RepositoryUrl | Should -Be $repo.html_url + } + + It 'Should have created a .gitignore file' { + { Get-GitHubContent -Uri $repo.svn_url -Path '.gitignore' } | Should -Not -Throw + } + + It 'Should have created a LICENSE file' { + { Get-GitHubContent -Uri $repo.svn_url -Path 'LICENSE' } | Should -Not -Throw + } + + AfterAll { + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + + Context 'When creating a public repository from a template (via pipeline input)' { + BeforeAll { + $repoName = ([Guid]::NewGuid().Guid) + $newRepoDesc = 'New Repo Description' $newGitHubRepositoryFromTemplateParms = @{ TargetOwnerName = $ownerName TargetRepositoryName = $repoName + Description = $newRepoDesc } - { $templateRepo | New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms -WhatIf } | - Should -Not -Throw + $repo = $templateRepo | New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms + Start-Sleep -Seconds 1 # To work around a delay that GitHub may have with generating the repo } It 'Should have the expected type and addititional properties' {