Skip to content

Commit 80c9c06

Browse files
committed
test: github
1 parent ed158fe commit 80c9c06

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

github/github_test.go

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package github
22

33
import (
4-
"fmt"
54
"testing"
65

76
"sqlpkg.org/cli/httpx"
@@ -29,41 +28,36 @@ func TestGetLatestTag(t *testing.T) {
2928

3029
func TestParseRepoUrl(t *testing.T) {
3130
type test struct {
32-
num int
31+
url string
3332
owner, repo string
3433
}
35-
valid := map[string]test{
36-
"https://github.com/nalgeon/sqlean": {0, "nalgeon", "sqlean"},
37-
"https://github.com/nalgeon/sqlean/": {1, "nalgeon", "sqlean"},
38-
"https://github.com/asg017/sqlite-vss": {2, "asg017", "sqlite-vss"},
34+
valid := []test{
35+
{"https://github.com/nalgeon/sqlean", "nalgeon", "sqlean"},
36+
{"https://github.com/nalgeon/sqlean/", "nalgeon", "sqlean"},
37+
{"https://github.com/asg017/sqlite-vss", "asg017", "sqlite-vss"},
3938
}
40-
for url, test := range valid {
41-
name := fmt.Sprintf("valid_%d", test.num)
42-
t.Run(name, func(t *testing.T) {
43-
owner, repo, err := ParseRepoUrl(url)
44-
if err != nil {
45-
t.Fatalf("ParseRepoUrl: unexpected error %v", err)
46-
}
47-
if owner != test.owner {
48-
t.Errorf("ParseRepoUrl: unexpected owner %v", test.owner)
49-
}
50-
if repo != test.repo {
51-
t.Errorf("ParseRepoUrl: unexpected name %v", test.repo)
52-
}
53-
})
39+
for _, test := range valid {
40+
owner, repo, err := ParseRepoUrl(test.url)
41+
if err != nil {
42+
t.Errorf("ParseRepoUrl(%s): unexpected error %v", test.url, err)
43+
continue
44+
}
45+
if owner != test.owner {
46+
t.Errorf("ParseRepoUrl(%s): unexpected owner %v", test.url, test.owner)
47+
}
48+
if repo != test.repo {
49+
t.Errorf("ParseRepoUrl(%s): unexpected name %v", test.url, test.repo)
50+
}
5451
}
5552

5653
invalid := []string{
5754
"https://github.com/nalgeon",
5855
"https://antonz.org",
5956
}
60-
for idx, url := range invalid {
61-
name := fmt.Sprintf("valid_%d", idx)
62-
t.Run(name, func(t *testing.T) {
63-
_, _, err := ParseRepoUrl(url)
64-
if err == nil {
65-
t.Fatal("ParseRepoUrl: expected error, got nil")
66-
}
67-
})
57+
for _, url := range invalid {
58+
_, _, err := ParseRepoUrl(url)
59+
if err == nil {
60+
t.Errorf("ParseRepoUrl(%s): expected error, got nil", url)
61+
}
6862
}
6963
}

0 commit comments

Comments
 (0)