mirror of
https://github.com/sky22333/hubproxy.git
synced 2026-09-30 12:16:38 +08:00
更新构建配置并补充测试
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package handlers
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCheckGitHubURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
url string
|
||||
user string
|
||||
repo string
|
||||
}{
|
||||
{"release", "https://github.com/user/repo/releases/download/v1/file.tar.gz", "user", "repo"},
|
||||
{"raw", "https://raw.githubusercontent.com/user/repo/main/file.sh", "user", "repo"},
|
||||
{"api", "https://api.github.com/repos/user/repo/releases/latest", "user", "repo"},
|
||||
{"huggingface", "https://huggingface.co/user/model/resolve/main/file", "user", "model/resolve/main/file"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := CheckGitHubURL(tt.url)
|
||||
if len(got) < 2 || got[0] != tt.user || got[1] != tt.repo {
|
||||
t.Fatalf("CheckGitHubURL(%q) = %#v", tt.url, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckGitHubURLRejectsOtherHosts(t *testing.T) {
|
||||
if got := CheckGitHubURL("https://example.com/user/repo/file"); got != nil {
|
||||
t.Fatalf("unexpected match: %#v", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user