Skip to content

Commit 74d751f

Browse files
leodidoona-agent
andcommitted
refactor(test): consolidate extractJobWorkflowRef test functions
Merge TestExtractJobWorkflowRef and TestExtractJobWorkflowRef_RealWorldExamples into a single test function. The 'real world' examples were just additional test cases, not fundamentally different scenarios. Benefits: - Single source of truth for extractJobWorkflowRef testing - Reduced duplication (removed 21 lines) - All 11 test cases still covered (basic + edge cases + real-world scenarios) Co-authored-by: Ona <[email protected]>
1 parent c180092 commit 74d751f

File tree

1 file changed

+20
-41
lines changed

1 file changed

+20
-41
lines changed

pkg/leeway/signing/attestation_test.go

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,26 @@ func TestExtractJobWorkflowRef(t *testing.T) {
11601160
subClaim: "repo:org/repo:ref:refs/heads/main:job_workflow_ref:org/repo/.github/workflows/build:test.yml@refs/heads/main",
11611161
expected: "org/repo/.github/workflows/build:test.yml@refs/heads/main",
11621162
},
1163+
{
1164+
name: "multiple colons in workflow path",
1165+
subClaim: "repo:org/repo:ref:refs/heads/main:job_workflow_ref:org/repo/.github/workflows/test:build:deploy.yml@refs/heads/main",
1166+
expected: "org/repo/.github/workflows/test:build:deploy.yml@refs/heads/main",
1167+
},
1168+
{
1169+
name: "reusable workflow with environment claim",
1170+
subClaim: "repo:gitpod-io/gitpod:environment:production:ref:refs/heads/main:job_workflow_ref:gitpod-io/gitpod/.github/workflows/_build-image.yml@refs/heads/main",
1171+
expected: "gitpod-io/gitpod/.github/workflows/_build-image.yml@refs/heads/main",
1172+
},
1173+
{
1174+
name: "pull request workflow",
1175+
subClaim: "repo:gitpod-io/leeway:ref:refs/pull/264/merge:job_workflow_ref:gitpod-io/leeway/.github/workflows/build.yml@refs/pull/264/merge",
1176+
expected: "gitpod-io/leeway/.github/workflows/build.yml@refs/pull/264/merge",
1177+
},
1178+
{
1179+
name: "tag-triggered workflow",
1180+
subClaim: "repo:org/repo:ref:refs/tags/v1.0.0:job_workflow_ref:org/repo/.github/workflows/release.yml@refs/tags/v1.0.0",
1181+
expected: "org/repo/.github/workflows/release.yml@refs/tags/v1.0.0",
1182+
},
11631183
{
11641184
name: "missing job_workflow_ref",
11651185
subClaim: "repo:example-org/example-repo:ref:refs/heads/main",
@@ -1180,11 +1200,6 @@ func TestExtractJobWorkflowRef(t *testing.T) {
11801200
subClaim: "repo:org/repo:ref:refs/heads/main:job_workflow_ref:",
11811201
expected: "",
11821202
},
1183-
{
1184-
name: "multiple colons in workflow path",
1185-
subClaim: "repo:org/repo:ref:refs/heads/main:job_workflow_ref:org/repo/.github/workflows/test:build:deploy.yml@refs/heads/main",
1186-
expected: "org/repo/.github/workflows/test:build:deploy.yml@refs/heads/main",
1187-
},
11881203
}
11891204

11901205
for _, tt := range tests {
@@ -1195,42 +1210,6 @@ func TestExtractJobWorkflowRef(t *testing.T) {
11951210
}
11961211
}
11971212

1198-
// TestExtractJobWorkflowRef_RealWorldExamples tests with actual GitHub OIDC token formats
1199-
func TestExtractJobWorkflowRef_RealWorldExamples(t *testing.T) {
1200-
tests := []struct {
1201-
name string
1202-
subClaim string
1203-
expected string
1204-
description string
1205-
}{
1206-
{
1207-
name: "GitHub Actions reusable workflow",
1208-
subClaim: "repo:gitpod-io/gitpod:environment:production:ref:refs/heads/main:job_workflow_ref:gitpod-io/gitpod/.github/workflows/_build-image.yml@refs/heads/main",
1209-
expected: "gitpod-io/gitpod/.github/workflows/_build-image.yml@refs/heads/main",
1210-
description: "Reusable workflow with environment claim",
1211-
},
1212-
{
1213-
name: "Pull request workflow",
1214-
subClaim: "repo:gitpod-io/leeway:ref:refs/pull/264/merge:job_workflow_ref:gitpod-io/leeway/.github/workflows/build.yml@refs/pull/264/merge",
1215-
expected: "gitpod-io/leeway/.github/workflows/build.yml@refs/pull/264/merge",
1216-
description: "Pull request merge ref",
1217-
},
1218-
{
1219-
name: "Tag-triggered workflow",
1220-
subClaim: "repo:org/repo:ref:refs/tags/v1.0.0:job_workflow_ref:org/repo/.github/workflows/release.yml@refs/tags/v1.0.0",
1221-
expected: "org/repo/.github/workflows/release.yml@refs/tags/v1.0.0",
1222-
description: "Tag reference",
1223-
},
1224-
}
1225-
1226-
for _, tt := range tests {
1227-
t.Run(tt.name, func(t *testing.T) {
1228-
result := extractJobWorkflowRef(tt.subClaim)
1229-
assert.Equal(t, tt.expected, result, tt.description)
1230-
})
1231-
}
1232-
}
1233-
12341213
// Helper function to create base64url encoded strings for JWT tokens
12351214
func base64EncodeForTest(s string) string {
12361215
return strings.TrimRight(base64.URLEncoding.EncodeToString([]byte(s)), "=")

0 commit comments

Comments
 (0)