Files
code-utils/clone_test.go

46 lines
1.5 KiB
Go
Raw Normal View History

2026-08-14 07:52:01 +08:00
package main
import "testing"
func TestRepoNameFromURL(t *testing.T) {
cases := map[string]string{
"https://github.com/user/my-repo.git": "my-repo",
"https://github.com/user/my-repo": "my-repo",
"https://github.com/user/my-repo/": "my-repo",
"git@github.com:user/awesome.git": "awesome",
"ssh://git@host:2222/team/svc.git": "svc",
"https://gitee.com/a/b c.git": "b-c",
" https://github.com/x/trim.git ": "trim",
"https://github.com/user/dots...git": "dots", // 残余尾点会被修剪Windows 目录名尾部点非法)
"https://github.com/user/UPPER.git": "UPPER",
`D:\code\my-repo`: "my-repo", // Windows 本地路径克隆
`D:\code\my-repo\`: "my-repo",
}
for in, want := range cases {
if got := repoNameFromURL(in); got != want {
t.Errorf("repoNameFromURL(%q)=%q want %q", in, got, want)
}
}
}
func TestCloneProgress(t *testing.T) {
cases := []struct {
line string
want int
ok bool
}{
{"Receiving objects: 0% (1/100)", 10, true},
{"Receiving objects: 100% (100/100), done.", 85, true},
{"Resolving deltas: 100% (50/50), done.", 98, true},
{"Counting objects: 50% (5/10)", 3, true},
{"Compressing objects: 100% (9/9), done.", 10, true},
{"Cloning into 'demo'...", 0, false},
}
for _, c := range cases {
got, ok := cloneProgress(c.line)
if ok != c.ok || got != c.want {
t.Errorf("cloneProgress(%q)=(%d,%v) want (%d,%v)", c.line, got, ok, c.want, c.ok)
}
}
}