Skip to content

Commit bae5ded

Browse files
Add GitHubWorkflowRun constructor regression test per review thread #3
Verifies all scalar properties are populated from the $Object parameter, not from the caller's $_. Constructing outside ForEach-Object ensures is null — if the constructor incorrectly references instead of , the assertions will fail.
1 parent ea253a5 commit bae5ded

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

tests/Actions.Tests.ps1

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,88 @@ BeforeAll {
2727
Describe 'Actions' {
2828
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"
2929

30+
Context 'GitHubWorkflowRun' {
31+
It 'Constructor should populate properties from $Object parameter, not from $_' {
32+
# Build a minimal mock object matching the GitHub REST API workflow-run response shape.
33+
# The constructor is called outside ForEach-Object so $_ is $null.
34+
# If the constructor incorrectly references $_ instead of $Object, scalar properties will be empty.
35+
$mockOwner = [PSCustomObject]@{
36+
id = 1
37+
node_id = 'MDQ6VXNlcjE='
38+
login = 'octocat'
39+
avatar_url = 'https://github.com/images/error/octocat_happy.gif'
40+
html_url = 'https://github.com/octocat'
41+
type = 'User'
42+
}
43+
44+
$mockRepo = [PSCustomObject]@{
45+
id = 100
46+
node_id = 'MDEwOlJlcG9zaXRvcnkxMDA='
47+
name = 'hello-world'
48+
full_name = 'octocat/hello-world'
49+
owner = $mockOwner
50+
html_url = 'https://github.com/octocat/hello-world'
51+
}
52+
53+
$mockUser = [PSCustomObject]@{
54+
id = 1
55+
node_id = 'MDQ6VXNlcjE='
56+
login = 'octocat'
57+
avatar_url = 'https://github.com/images/error/octocat_happy.gif'
58+
html_url = 'https://github.com/octocat'
59+
type = 'User'
60+
}
61+
62+
$mockRun = [PSCustomObject]@{
63+
id = 42
64+
node_id = 'MDExOldvcmtmbG93UnVuNDI='
65+
name = 'CI Build'
66+
check_suite_id = 99
67+
check_suite_node_id = 'MDEwOkNoZWNrU3VpdGU5OQ=='
68+
head_branch = 'main'
69+
head_sha = '009b8a3a9ccbb128af87f9b1c0f4c62e8a304f6d'
70+
path = '.github/workflows/ci.yml'
71+
run_number = 106
72+
run_attempt = 1
73+
event = 'push'
74+
status = 'completed'
75+
conclusion = 'success'
76+
workflow_id = 5
77+
html_url = 'https://github.com/octocat/hello-world/actions/runs/42'
78+
display_title = 'CI Build'
79+
created_at = '2023-01-01T12:00:00Z'
80+
updated_at = '2023-01-01T12:05:00Z'
81+
run_started_at = '2023-01-01T12:01:00Z'
82+
pull_requests = @()
83+
referenced_workflows = @()
84+
repository = $mockRepo
85+
head_repository = $mockRepo
86+
actor = $mockUser
87+
triggering_actor = $mockUser
88+
head_commit = [PSCustomObject]@{ id = 'abc123'; message = 'Test commit' }
89+
}
90+
91+
$result = [GitHubWorkflowRun]::new($mockRun)
92+
93+
$result.ID | Should -Be 42
94+
$result.NodeID | Should -Be 'MDExOldvcmtmbG93UnVuNDI='
95+
$result.Name | Should -Be 'CI Build'
96+
$result.CheckSuiteID | Should -Be 99
97+
$result.CheckSuiteNodeID | Should -Be 'MDEwOkNoZWNrU3VpdGU5OQ=='
98+
$result.HeadBranch | Should -Be 'main'
99+
$result.HeadSha | Should -Be '009b8a3a9ccbb128af87f9b1c0f4c62e8a304f6d'
100+
$result.Path | Should -Be '.github/workflows/ci.yml'
101+
$result.RunNumber | Should -Be 106
102+
$result.RunAttempt | Should -Be 1
103+
$result.Event | Should -Be 'push'
104+
$result.Status | Should -Be 'completed'
105+
$result.Conclusion | Should -Be 'success'
106+
$result.WorkflowID | Should -Be 5
107+
$result.Url | Should -Be 'https://github.com/octocat/hello-world/actions/runs/42'
108+
$result.DisplayTitle | Should -Be 'CI Build'
109+
}
110+
}
111+
30112
Context 'OIDC' {
31113
Context 'Get-GitHubOidcClaim' {
32114
It 'Get-GitHubOidcClaim - No context - Returns claim keys for github.com' {

0 commit comments

Comments
 (0)