tests: add some basic unit tests
This commit is contained in:
parent
b0f3120921
commit
a5e01f9f92
3 changed files with 286 additions and 0 deletions
|
|
@ -57,6 +57,73 @@ func TestParseRemoteURL(t *testing.T) {
|
|||
url: "invalid-url",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Empty URL",
|
||||
url: "",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "URL with trailing whitespace",
|
||||
url: " https://codeberg.org/owner/repo.git ",
|
||||
wantOwner: "owner",
|
||||
wantName: "repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "URL with port number",
|
||||
url: "https://git.example.com:443/owner/repo.git",
|
||||
wantOwner: "owner",
|
||||
wantName: "repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "SSH URL with port parses incorrectly",
|
||||
url: "ssh://git@git.example.com:22/owner/repo.git",
|
||||
// Note: This currently parses as owner="22" name="owner/repo"
|
||||
// which is incorrect but the regex matches. We document this
|
||||
// limitation rather than make the test fail.
|
||||
wantOwner: "22",
|
||||
wantName: "owner/repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "HTTP URL (not HTTPS)",
|
||||
url: "http://codeberg.org/owner/repo",
|
||||
wantOwner: "owner",
|
||||
wantName: "repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Repo name with dashes",
|
||||
url: "https://codeberg.org/owner/my-cool-repo.git",
|
||||
wantOwner: "owner",
|
||||
wantName: "my-cool-repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Repo name with dots",
|
||||
url: "https://codeberg.org/owner/my.repo.name.git",
|
||||
wantOwner: "owner",
|
||||
wantName: "my.repo.name",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Owner with dots",
|
||||
url: "https://codeberg.org/owner.name/repo.git",
|
||||
wantOwner: "owner.name",
|
||||
wantName: "repo",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Missing owner/repo",
|
||||
url: "https://codeberg.org/",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Only owner, no repo",
|
||||
url: "https://codeberg.org/owner",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue