Skip to content

Commit c63496c

Browse files
committed
Add UT for testing labels added at Issue creation time
Issue #76 recent fixed a bug where Labels were not being correctly added to Issues at the time of creation. This new UT will ensure that is always tested going forward. Additionally, this updates all UT's to disable telemetry and enable logging of the request body to ease debugging.
1 parent 3b6e84c commit c63496c

9 files changed

+358
-305
lines changed

Tests/GitHubAnalytics.tests.ps1

Lines changed: 240 additions & 232 deletions
Large diffs are not rendered by default.

Tests/GitHubAssignees.tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ if (-not $script:accessTokenConfigured)
7070
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
7171
# the tests. We'll restore it at the end.
7272
$configFile = New-TemporaryFile
73+
7374
try
7475
{
7576
Backup-GitHubConfiguration -Path $configFile
7677
Reset-GitHubConfiguration
7778
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
79+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7880

7981
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
8082
$issue = New-GitHubIssue -Uri $repo.svn_url -Title "Test issue"

Tests/GitHubComments.tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ try
7575
Backup-GitHubConfiguration -Path $configFile
7676
Reset-GitHubConfiguration
7777
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
78+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7879

7980
# Define Script-scoped, readonly, hidden variables.
8081

Tests/GitHubCore.Tests.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ if (-not $script:accessTokenConfigured)
6767
Write-Warning -Message ($message -join [Environment]::NewLine)
6868
}
6969

70+
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
71+
# the tests. We'll restore it at the end.
72+
$configFile = New-TemporaryFile
73+
7074
try
7175
{
72-
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
73-
# the tests. We'll restore it at the end.
74-
$configFile = New-TemporaryFile
7576
Backup-GitHubConfiguration -Path $configFile
7677
Reset-GitHubConfiguration
7778
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
79+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7880

7981
Describe 'Testing ConvertTo-SmarterObject behavior' {
8082
InModuleScope PowerShellForGitHub {

Tests/GitHubEvents.tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ try
7575
{
7676
Backup-GitHubConfiguration -Path $configFile
7777
Reset-GitHubConfiguration
78+
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
79+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7880

7981
if ($accessTokenConfigured)
8082
{

Tests/GitHubLabels.tests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ if (-not $accessTokenConfigured)
7070
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
7171
# the tests. We'll restore it at the end.
7272
$configFile = New-TemporaryFile
73+
7374
try
7475
{
7576
Backup-GitHubConfiguration -Path $configFile
7677
Reset-GitHubConfiguration
78+
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
79+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7780

7881
$defaultLabels = @(
7982
@{
@@ -300,6 +303,23 @@ try
300303

301304
$null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName
302305
}
306+
307+
Describe 'Creating a new Issue with labels' {
308+
$repositoryName = [Guid]::NewGuid().Guid
309+
$null = New-GitHubRepository -RepositoryName $repositoryName
310+
Set-GitHubLabel -OwnerName $ownerName -RepositoryName $repositoryName -Label $defaultLabels
311+
312+
$issueName = [Guid]::NewGuid().Guid
313+
$issueLabels = @($defaultLabels[0].name, $defaultLabels[1].name)
314+
$issue = New-GitHubIssue -OwnerName $ownerName -RepositoryName $repositoryName -Title $issueName -Label $issueLabels
315+
316+
It 'Should return the number of labels that were just added' {
317+
$issue.labels.Count | Should be $issueLabels.Count
318+
}
319+
320+
$null = Remove-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName
321+
}
322+
303323
Describe 'Removing labels on an issue'{
304324
$repositoryName = [Guid]::NewGuid().Guid
305325
$null = New-GitHubRepository -RepositoryName $repositoryName

Tests/GitHubMilestones.tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ if (-not $script:accessTokenConfigured)
7070
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
7171
# the tests. We'll restore it at the end.
7272
$configFile = New-TemporaryFile
73+
7374
try
7475
{
7576
Backup-GitHubConfiguration -Path $configFile
7677
Reset-GitHubConfiguration
7778
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
79+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7880

7981
# Define Script-scoped, readonly, hidden variables.
8082

Tests/GitHubRepositoryForks.tests.ps1

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,46 +70,54 @@ if (-not $script:accessTokenConfigured)
7070
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
7171
# the tests. We'll restore it at the end.
7272
$configFile = New-TemporaryFile
73-
Backup-GitHubConfiguration -Path $configFile
74-
Reset-GitHubConfiguration
7573

76-
Describe 'Creating a new fork for user' {
77-
$originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub
74+
try
75+
{
76+
Backup-GitHubConfiguration -Path $configFile
77+
Reset-GitHubConfiguration
78+
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
79+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7880

79-
Context 'When a new fork is created' {
80-
$repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub
81-
$newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest
81+
Describe 'Creating a new fork for user' {
82+
$originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub
8283

83-
It 'Should have one more fork than before' {
84-
(@($newForks).Count - @($originalForks).Count) | Should be 1
85-
}
84+
Context 'When a new fork is created' {
85+
$repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub
86+
$newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest
8687

87-
It 'Should be the latest fork in the list' {
88-
$newForks[0].full_name | Should be "$($script:ownerName)/PowerShellForGitHub"
89-
}
88+
It 'Should have one more fork than before' {
89+
(@($newForks).Count - @($originalForks).Count) | Should be 1
90+
}
9091

91-
Remove-GitHubRepository -Uri $repo.svn_url
92+
It 'Should be the latest fork in the list' {
93+
$newForks[0].full_name | Should be "$($script:ownerName)/PowerShellForGitHub"
94+
}
95+
96+
Remove-GitHubRepository -Uri $repo.svn_url
97+
}
9298
}
93-
}
9499

95-
Describe 'Creating a new fork for an org' {
96-
$originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub
100+
Describe 'Creating a new fork for an org' {
101+
$originalForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub
97102

98-
Context 'When a new fork is created' {
99-
$repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -OrganizationName $script:organizationName
100-
$newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest
103+
Context 'When a new fork is created' {
104+
$repo = New-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -OrganizationName $script:organizationName
105+
$newForks = Get-GitHubRepositoryFork -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Sort newest
101106

102-
It 'Should have one more fork than before' {
103-
(@($newForks).Count - @($originalForks).Count) | Should be 1
104-
}
107+
It 'Should have one more fork than before' {
108+
(@($newForks).Count - @($originalForks).Count) | Should be 1
109+
}
105110

106-
It 'Should be the latest fork in the list' {
107-
$newForks[0].full_name | Should be "$($script:organizationName)/PowerShellForGitHub"
108-
}
111+
It 'Should be the latest fork in the list' {
112+
$newForks[0].full_name | Should be "$($script:organizationName)/PowerShellForGitHub"
113+
}
109114

110-
Remove-GitHubRepository -Uri $repo.svn_url
115+
Remove-GitHubRepository -Uri $repo.svn_url
116+
}
111117
}
112118
}
113-
114-
# Restore the user's configuration to its pre-test state
115-
Restore-GitHubConfiguration -Path $configFile
119+
finally
120+
{
121+
# Restore the user's configuration to its pre-test state
122+
Restore-GitHubConfiguration -Path $configFile
123+
}

Tests/GitHubRepositoryTraffic.tests.ps1

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -70,64 +70,72 @@ if (-not $script:accessTokenConfigured)
7070
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
7171
# the tests. We'll restore it at the end.
7272
$configFile = New-TemporaryFile
73-
Backup-GitHubConfiguration -Path $configFile
74-
Reset-GitHubConfiguration
7573

76-
Describe 'Getting the referrer list' {
77-
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
74+
try
75+
{
76+
Backup-GitHubConfiguration -Path $configFile
77+
Reset-GitHubConfiguration
78+
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
79+
Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures
7880

79-
Context 'When initially created, there are no referrers' {
80-
$referrerList = Get-GitHubReferrerTraffic -Uri $repo.svn_url
81+
Describe 'Getting the referrer list' {
82+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
8183

82-
It 'Should return expected number of referrers' {
83-
@($referrerList).Count | Should be 0
84-
}
84+
Context 'When initially created, there are no referrers' {
85+
$referrerList = Get-GitHubReferrerTraffic -Uri $repo.svn_url
8586

86-
Remove-GitHubRepository -Uri $repo.svn_url
87+
It 'Should return expected number of referrers' {
88+
@($referrerList).Count | Should be 0
89+
}
90+
91+
Remove-GitHubRepository -Uri $repo.svn_url
92+
}
8793
}
88-
}
8994

90-
Describe 'Getting the popular content over the last 14 days' {
91-
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
95+
Describe 'Getting the popular content over the last 14 days' {
96+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
9297

93-
Context 'When initially created, there are is no popular content' {
94-
$pathList = Get-GitHubPathTraffic -Uri $repo.svn_url
98+
Context 'When initially created, there are is no popular content' {
99+
$pathList = Get-GitHubPathTraffic -Uri $repo.svn_url
95100

96-
It 'Should return expected number of popular content' {
97-
@($pathList).Count | Should be 0
98-
}
101+
It 'Should return expected number of popular content' {
102+
@($pathList).Count | Should be 0
103+
}
99104

100-
Remove-GitHubRepository -Uri $repo.svn_url
105+
Remove-GitHubRepository -Uri $repo.svn_url
106+
}
101107
}
102-
}
103108

104-
Describe 'Getting the views over the last 14 days' {
105-
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
109+
Describe 'Getting the views over the last 14 days' {
110+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
106111

107-
Context 'When initially created, there are no views' {
108-
$viewList = Get-GitHubViewTraffic -Uri $repo.svn_url
112+
Context 'When initially created, there are no views' {
113+
$viewList = Get-GitHubViewTraffic -Uri $repo.svn_url
109114

110-
It 'Should return 0 in the count property' {
111-
$viewList.Count | Should be 0
112-
}
115+
It 'Should return 0 in the count property' {
116+
$viewList.Count | Should be 0
117+
}
113118

114-
Remove-GitHubRepository -Uri $repo.svn_url
119+
Remove-GitHubRepository -Uri $repo.svn_url
120+
}
115121
}
116-
}
117122

118-
Describe 'Getting the clones over the last 14 days' {
119-
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
123+
Describe 'Getting the clones over the last 14 days' {
124+
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
120125

121-
Context 'When initially created, there is 0 clones' {
122-
$cloneList = Get-GitHubCloneTraffic -Uri $repo.svn_url
126+
Context 'When initially created, there is 0 clones' {
127+
$cloneList = Get-GitHubCloneTraffic -Uri $repo.svn_url
123128

124-
It 'Should return expected number of clones' {
125-
$cloneList.Count | Should be 0
126-
}
129+
It 'Should return expected number of clones' {
130+
$cloneList.Count | Should be 0
131+
}
127132

128-
Remove-GitHubRepository -Uri $repo.svn_url
133+
Remove-GitHubRepository -Uri $repo.svn_url
134+
}
129135
}
130136
}
131-
132-
# Restore the user's configuration to its pre-test state
133-
Restore-GitHubConfiguration -Path $configFile
137+
finally
138+
{
139+
# Restore the user's configuration to its pre-test state
140+
Restore-GitHubConfiguration -Path $configFile
141+
}

0 commit comments

Comments
 (0)