-
Notifications
You must be signed in to change notification settings - Fork 8
/
aur_test.go
134 lines (112 loc) · 3.45 KB
/
aur_test.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package aur
import (
"net/http"
"net/url"
"testing"
)
func expectPackages(t *testing.T, n int, rs []Pkg, err error) {
if err != nil {
t.Error(err)
}
if len(rs) < n {
t.Errorf("Expected more than %d packages, got '%d'", n, len(rs))
}
}
func expectTooMany(t *testing.T, rs []Pkg, err error) {
if err.Error() != "Too many package results." {
t.Errorf("Expected error 'Too many package results.', got '%s'", err.Error())
}
if len(rs) > 0 {
t.Errorf("Expected no results, got '%d'", len(rs))
}
}
func expectError(t *testing.T, expected error, actual error) {
if expected != actual {
t.Errorf(`Expected error is "%s", but actual "%s"`, expected, actual)
}
}
func TestGetError(t *testing.T) {
_, err := get(url.Values{})
if err == nil {
t.Error("This case must fail")
}
AURURL = "http://localhost"
_, err = get(url.Values{})
if err == nil {
t.Error("This case must fail")
}
AURURL = "https://aur.archlinux.org/rpc.php?"
}
// TestInfo test getting info for multiple packages
func TestInfo(t *testing.T) {
rs, err := Info([]string{"neovim-git", "linux-mainline"})
if err != nil {
t.Error(err)
}
if len(rs) != 2 {
t.Errorf("Expected two packages, got %d", len(rs))
}
}
// TestSearch test searching for packages by the AUR's default by field
func TestSearch(t *testing.T) {
rs, err := Search("linux")
expectPackages(t, 100, rs, err)
rs, err = Search("li")
expectTooMany(t, rs, err)
}
// TestSearchByName test searching for packages by package name
func TestSearchByName(t *testing.T) {
rs, err := SearchBy("linux", Name)
expectPackages(t, 100, rs, err)
}
// TestSearchByNameDesc test searching for packages package name and desc.
func TestSearchByNameDesc(t *testing.T) {
rs, err := SearchBy("linux", NameDesc)
expectPackages(t, 100, rs, err)
}
// TestSearchByMaintainer test searching for packages by maintainer
func TestSearchByMaintainer(t *testing.T) {
rs, err := SearchBy("moscar", Maintainer)
expectPackages(t, 3, rs, err)
}
// TestSearchError test wrong By
func TestSearchPanic(t *testing.T) {
defer func() {
if recover() == nil {
t.Error("This case must fail")
}
}()
_ = By(0).String()
}
// Currently orphan searching is broken due to https://bugs.archlinux.org/task/62388
// TestOrphans test searching for orphans
//func TestOrphans(t *testing.T) {
// rs, err := Orphans()
// expectPackages(t, 500, rs, err)
//}
// TestSearchByDepends test searching for packages by depends
func TestSearchByDepends(t *testing.T) {
rs, err := SearchBy("python", Depends)
expectPackages(t, 100, rs, err)
}
// TestSearchByMakeDepends test searching for packages by makedepends
func TestSearchByMakeDepends(t *testing.T) {
rs, err := SearchBy("python", MakeDepends)
expectPackages(t, 100, rs, err)
}
// TestSearchByOptDepends test searching for packages by optdepends
func TestSearchByOptDepends(t *testing.T) {
rs, err := SearchBy("python", OptDepends)
expectPackages(t, 100, rs, err)
}
// TestSearchByCheckDepends test searching for packages by checkdepends
func TestSearchByCheckDepends(t *testing.T) {
rs, err := SearchBy("python", CheckDepends)
expectPackages(t, 10, rs, err)
}
// TestGetErrorByStatusCode test get error by HTTP status code
func TestGetErrorByStatusCode(t *testing.T) {
expectError(t, ErrServiceUnavailable, getErrorByStatusCode(http.StatusBadGateway))
expectError(t, ErrServiceUnavailable, getErrorByStatusCode(http.StatusGatewayTimeout))
expectError(t, ErrServiceUnavailable, getErrorByStatusCode(http.StatusServiceUnavailable))
}