TestParseGitHubURL tests the parseGitHubURL function directly
(t *testing.T)
| 8 | |
| 9 | // TestParseGitHubURL tests the parseGitHubURL function directly |
| 10 | func TestParseGitHubURL(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | url string |
| 14 | wantRepo string |
| 15 | wantWorkflowPath string |
| 16 | wantWorkflowName string |
| 17 | wantVersion string |
| 18 | wantErr bool |
| 19 | errContains string |
| 20 | }{ |
| 21 | { |
| 22 | name: "blob URL with main branch", |
| 23 | url: "https://github.com/github/gh-aw-trial/blob/main/workflows/release-issue-linker.md", |
| 24 | wantRepo: "github/gh-aw-trial", |
| 25 | wantWorkflowPath: "workflows/release-issue-linker.md", |
| 26 | wantWorkflowName: "release-issue-linker", |
| 27 | wantVersion: "main", |
| 28 | wantErr: false, |
| 29 | }, |
| 30 | { |
| 31 | name: "tree URL with develop branch", |
| 32 | url: "https://github.com/owner/repo/tree/develop/custom/path/workflow.md", |
| 33 | wantRepo: "owner/repo", |
| 34 | wantWorkflowPath: "custom/path/workflow.md", |
| 35 | wantWorkflowName: "workflow", |
| 36 | wantVersion: "develop", |
| 37 | wantErr: false, |
| 38 | }, |
| 39 | { |
| 40 | name: "raw URL with version tag", |
| 41 | url: "https://github.com/owner/repo/raw/v2.0.0/workflows/helper.md", |
| 42 | wantRepo: "owner/repo", |
| 43 | wantWorkflowPath: "workflows/helper.md", |
| 44 | wantWorkflowName: "helper", |
| 45 | wantVersion: "v2.0.0", |
| 46 | wantErr: false, |
| 47 | }, |
| 48 | { |
| 49 | name: "blob URL with long hyphenated repo name", |
| 50 | url: "https://github.com/owner/this-repository-name-is-significantly-longer-than-thirty-nine/blob/main/workflows/release.md", |
| 51 | wantRepo: "owner/this-repository-name-is-significantly-longer-than-thirty-nine", |
| 52 | wantWorkflowPath: "workflows/release.md", |
| 53 | wantWorkflowName: "release", |
| 54 | wantVersion: "main", |
| 55 | wantErr: false, |
| 56 | }, |
| 57 | { |
| 58 | name: "invalid - non-github domain", |
| 59 | url: "https://gitlab.com/owner/repo/blob/main/workflows/test.md", |
| 60 | wantErr: true, |
| 61 | errContains: "must be from github.com", |
| 62 | }, |
| 63 | { |
| 64 | name: "invalid - path too short", |
| 65 | url: "https://github.com/owner/repo/blob/main", |
| 66 | wantErr: true, |
| 67 | errContains: "path too short", |
nothing calls this directly
no test coverage detected