| 1 | package github |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestOwnerRepoFromPRURL(t *testing.T) { |
| 6 | tests := []struct { |
| 7 | name string |
| 8 | url string |
| 9 | want string |
| 10 | }{ |
| 11 | {"standard PR URL", "https://github.com/maintainer/klaus/pull/270", "maintainer/klaus"}, |
| 12 | {"http scheme", "http://github.com/owner/repo/pull/1", "owner/repo"}, |
| 13 | {"trailing slash after repo", "https://github.com/owner/repo/", "owner/repo"}, |
| 14 | {"owner/repo only", "https://github.com/owner/repo", "owner/repo"}, |
| 15 | {"bare short name returns empty", "klaus", ""}, |
| 16 | {"malformed URL returns empty", "not-a-url", ""}, |
| 17 | {"owner only returns empty", "https://github.com/owner", ""}, |
| 18 | {"empty string returns empty", "", ""}, |
| 19 | {"empty repo segment returns empty", "https://github.com/owner//pull/1", ""}, |
| 20 | } |
| 21 | for _, tt := range tests { |
| 22 | t.Run(tt.name, func(t *testing.T) { |
| 23 | if got := OwnerRepoFromPRURL(tt.url); got != tt.want { |
| 24 | t.Errorf("OwnerRepoFromPRURL(%q) = %q, want %q", tt.url, got, tt.want) |
| 25 | } |
| 26 | }) |
| 27 | } |
| 28 | } |