11
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package git_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"superwork-tui/internal/git"
|
||||
)
|
||||
|
||||
func TestParseRemoteURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
url string
|
||||
wantHost string
|
||||
wantOwner string
|
||||
wantRepo string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "https with .git",
|
||||
url: "https://gitea.example.com/owner/repo.git",
|
||||
wantHost: "gitea.example.com",
|
||||
wantOwner: "owner",
|
||||
wantRepo: "repo",
|
||||
},
|
||||
{
|
||||
name: "https without .git",
|
||||
url: "https://gitea.example.com/owner/repo",
|
||||
wantHost: "gitea.example.com",
|
||||
wantOwner: "owner",
|
||||
wantRepo: "repo",
|
||||
},
|
||||
{
|
||||
name: "https with trailing slash",
|
||||
url: "https://gitea.example.com/owner/repo.git/",
|
||||
wantHost: "gitea.example.com",
|
||||
wantOwner: "owner",
|
||||
wantRepo: "repo",
|
||||
},
|
||||
{
|
||||
name: "ssh git@ form",
|
||||
url: "git@gitea.example.com:owner/repo.git",
|
||||
wantHost: "gitea.example.com",
|
||||
wantOwner: "owner",
|
||||
wantRepo: "repo",
|
||||
},
|
||||
{
|
||||
name: "ssh:// form",
|
||||
url: "ssh://git@gitea.example.com/owner/repo.git",
|
||||
wantHost: "gitea.example.com",
|
||||
wantOwner: "owner",
|
||||
wantRepo: "repo",
|
||||
},
|
||||
{
|
||||
name: "ssh git@ without .git",
|
||||
url: "git@gitea.example.com:owner/repo",
|
||||
wantHost: "gitea.example.com",
|
||||
wantOwner: "owner",
|
||||
wantRepo: "repo",
|
||||
},
|
||||
{
|
||||
name: "empty URL",
|
||||
url: "",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid URL",
|
||||
url: "not-a-url",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := git.ParseRemoteURL(tt.url)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatal("want error, got nil")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if got.Host != tt.wantHost {
|
||||
t.Errorf("Host: got %q, want %q", got.Host, tt.wantHost)
|
||||
}
|
||||
if got.Owner != tt.wantOwner {
|
||||
t.Errorf("Owner: got %q, want %q", got.Owner, tt.wantOwner)
|
||||
}
|
||||
if got.Repo != tt.wantRepo {
|
||||
t.Errorf("Repo: got %q, want %q", got.Repo, tt.wantRepo)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user