This repository was archived by the owner on Feb 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgithub_test.go
More file actions
63 lines (58 loc) · 1.45 KB
/
github_test.go
File metadata and controls
63 lines (58 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package github
import (
"testing"
"sqlpkg.org/cli/httpx"
)
func TestGetLatestTag(t *testing.T) {
t.Run("valid", func(t *testing.T) {
httpx.Mock("valid")
tag, err := GetLatestTag("nalgeon", "sqlean")
if err != nil {
t.Fatalf("GetLatestTag: unexpected error %v", err)
}
if tag != "0.21.6" {
t.Errorf("GetLatestTag: unexpected tag %v", tag)
}
})
t.Run("invalid", func(t *testing.T) {
httpx.Mock()
_, err := GetLatestTag("nalgeon", "sqlean")
if err == nil {
t.Fatal("GetLatestTag: expected error, got nil")
}
})
}
func TestParseRepoUrl(t *testing.T) {
type test struct {
url string
owner, repo string
}
valid := []test{
{"https://github.com/nalgeon/sqlean", "nalgeon", "sqlean"},
{"https://github.com/nalgeon/sqlean/", "nalgeon", "sqlean"},
{"https://github.com/asg017/sqlite-vss", "asg017", "sqlite-vss"},
}
for _, test := range valid {
owner, repo, err := ParseRepoUrl(test.url)
if err != nil {
t.Errorf("ParseRepourl(?url=https%3A%2F%2Fgithub.com%2Fnalgeon%2Fsqlpkg-cli%2Fblob%2Fmain%2Fgithub%2Fgithub_test.go%2F%25s): unexpected error %v", test.url, err)
continue
}
if owner != test.owner {
t.Errorf("ParseRepourl(?url=https%3A%2F%2Fgithub.com%2Fnalgeon%2Fsqlpkg-cli%2Fblob%2Fmain%2Fgithub%2Fgithub_test.go%2F%25s): unexpected owner %v", test.url, test.owner)
}
if repo != test.repo {
t.Errorf("ParseRepourl(?url=https%3A%2F%2Fgithub.com%2Fnalgeon%2Fsqlpkg-cli%2Fblob%2Fmain%2Fgithub%2Fgithub_test.go%2F%25s): unexpected name %v", test.url, test.repo)
}
}
invalid := []string{
"https://github.com/nalgeon",
"https://antonz.org",
}
for _, url := range invalid {
_, _, err := ParseRepoUrl(url)
if err == nil {
t.Errorf("ParseRepourl(?url=https%3A%2F%2Fgithub.com%2Fnalgeon%2Fsqlpkg-cli%2Fblob%2Fmain%2Fgithub%2Fgithub_test.go%2F%25s): expected error, got nil", url)
}
}
}