| 67 | } |
| 68 | |
| 69 | func TestParseURL(t *testing.T) { |
| 70 | type url struct { |
| 71 | Scheme string |
| 72 | User string |
| 73 | Host string |
| 74 | Path string |
| 75 | } |
| 76 | tests := []struct { |
| 77 | name string |
| 78 | url string |
| 79 | want url |
| 80 | wantErr bool |
| 81 | }{ |
| 82 | { |
| 83 | name: "HTTPS", |
| 84 | url: "https://example.com/owner/repo.git", |
| 85 | want: url{ |
| 86 | Scheme: "https", |
| 87 | User: "", |
| 88 | Host: "example.com", |
| 89 | Path: "/owner/repo.git", |
| 90 | }, |
| 91 | }, |
| 92 | { |
| 93 | name: "HTTP", |
| 94 | url: "http://example.com/owner/repo.git", |
| 95 | want: url{ |
| 96 | Scheme: "http", |
| 97 | User: "", |
| 98 | Host: "example.com", |
| 99 | Path: "/owner/repo.git", |
| 100 | }, |
| 101 | }, |
| 102 | { |
| 103 | name: "git", |
| 104 | url: "git://example.com/owner/repo.git", |
| 105 | want: url{ |
| 106 | Scheme: "git", |
| 107 | User: "", |
| 108 | Host: "example.com", |
| 109 | Path: "/owner/repo.git", |
| 110 | }, |
| 111 | }, |
| 112 | { |
| 113 | name: "ssh", |
| 114 | url: "ssh://git@example.com/owner/repo.git", |
| 115 | want: url{ |
| 116 | Scheme: "ssh", |
| 117 | User: "git", |
| 118 | Host: "example.com", |
| 119 | Path: "/owner/repo.git", |
| 120 | }, |
| 121 | }, |
| 122 | { |
| 123 | name: "ssh with port", |
| 124 | url: "ssh://git@example.com:443/owner/repo.git", |
| 125 | want: url{ |
| 126 | Scheme: "ssh", |