basic clone capabilities
This commit is contained in:
commit
d3647b71d7
3 changed files with 227 additions and 0 deletions
105
parseurl_test.go
Normal file
105
parseurl_test.go
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseGitURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
inputURL string
|
||||
expectedHost string
|
||||
expectedPath string
|
||||
expectError bool
|
||||
}{
|
||||
// 1. Standard HTTPS (Github)
|
||||
{
|
||||
name: "HTTPS Github",
|
||||
inputURL: "https://github.com/juancwu/dotfiles",
|
||||
expectedHost: "github.com",
|
||||
expectedPath: "juancwu/dotfiles",
|
||||
},
|
||||
// 2. SSH Short Syntax (Github)
|
||||
{
|
||||
name: "SSH Github",
|
||||
inputURL: "git@github.com:juancwu/dotfiles",
|
||||
expectedHost: "github.com",
|
||||
expectedPath: "juancwu/dotfiles",
|
||||
},
|
||||
// 3. SSH with .git extension
|
||||
{
|
||||
name: "SSH Github with .git",
|
||||
inputURL: "git@github.com:juancwu/dotfiles.git",
|
||||
expectedHost: "github.com",
|
||||
expectedPath: "juancwu/dotfiles",
|
||||
},
|
||||
// 4. SSH with Tilde (Home directory reference)
|
||||
// Note: The parser captures the path literally.
|
||||
{
|
||||
name: "SSH Github Tilde",
|
||||
inputURL: "git@github.com:~/juancwu/dotfiles",
|
||||
expectedHost: "github.com",
|
||||
expectedPath: "~/juancwu/dotfiles",
|
||||
},
|
||||
// 5. Custom Domain / Subdomain
|
||||
{
|
||||
name: "Custom Domain SSH",
|
||||
inputURL: "git@git.juancwu.dev:juancwu/dotfiles",
|
||||
expectedHost: "git.juancwu.dev",
|
||||
expectedPath: "juancwu/dotfiles",
|
||||
},
|
||||
// 6. Deeply Nested (Gitlab Subgroups)
|
||||
{
|
||||
name: "Gitlab Nested Group HTTPS",
|
||||
inputURL: "https://gitlab.com/organization/backend/services/auth.git",
|
||||
expectedHost: "gitlab.com",
|
||||
expectedPath: "organization/backend/services/auth",
|
||||
},
|
||||
// 7. Standard SSH Scheme (ssh://)
|
||||
{
|
||||
name: "SSH Scheme Standard",
|
||||
inputURL: "ssh://git@github.com/juancwu/dotfiles",
|
||||
expectedHost: "github.com",
|
||||
expectedPath: "juancwu/dotfiles",
|
||||
},
|
||||
// 8. IP Address Host
|
||||
{
|
||||
name: "IP Address Host",
|
||||
inputURL: "http://192.168.1.50/user/repo.git",
|
||||
expectedHost: "192.168.1.50",
|
||||
expectedPath: "user/repo",
|
||||
},
|
||||
// 9. Invalid URL
|
||||
{
|
||||
name: "Empty String",
|
||||
inputURL: "",
|
||||
expectError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result, err := parseGitURL(tt.inputURL)
|
||||
|
||||
if tt.expectError {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error for input '%s', but got nil", tt.inputURL)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error for input '%s': %v", tt.inputURL, err)
|
||||
return
|
||||
}
|
||||
|
||||
if result.Host != tt.expectedHost {
|
||||
t.Errorf("Host mismatch.\nExpected: %s\nGot: %s", tt.expectedHost, result.Host)
|
||||
}
|
||||
|
||||
if result.Path != tt.expectedPath {
|
||||
t.Errorf("Path mismatch.\nExpected: %s\nGot: %s", tt.expectedPath, result.Path)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue