/
deb_test.go
91 lines (87 loc) · 1.97 KB
/
deb_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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
const debbody = `<html>
<head>
<title>Debian Maintainer Dashboard</title>
</head>
<body>
<div id="content">
<h2 id='versions'>Versions</h2>
<table class="tablesorter table table-bordered">
<thead>
<tr>
<th>source</th>
<th>squeeze</th>
<th>wheezy</th>
<th>jessie</th>
<th>sid</th>
<th>experimental</th>
<th>vcs</th>
<th>upstream</th>
</tr>
</thead>
<tbody>
<tr><td><a href="https://tracker.debian.org/example0" title="Maintained by Alice">example0</a></td>
<td>
</td>
<td>
0.3.3-1
</td>
<td colspan="2" class="center">
0.5.1-1
</td>
<td colspan="2" class="center">
</td>
<td>
<span class="prio_high" title="Newer upstream version available">0.5.3</a>
</td>
</tr>
<tr><td><a href="https://tracker.debian.org/example1" title="Maintained by Alice">example1</a></td>
<td colspan="2" class="center">
</td>
<td colspan="2" class="center">
0.8-1
</td>
<td colspan="2" class="center">
</td>
<td>
<span class="prio_high" title="Newer upstream version available">0.8.2</a>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
`
func TestDebPackages(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, debbody)
}))
defer ts.Close()
var srv = service{"debian", "guest@example.org", ""}
srv.uri = ts.URL
d, err := srv.debPackages()
if err != nil {
t.Fatalf("%v", err)
}
for i, v := range d {
if v.(deb).Source != fmt.Sprintf("example%d", i) {
t.Fatalf("%v, want: example%d\n", v.(deb).Source, i)
}
if v.(deb).URL != fmt.Sprintf("https://tracker.debian.org/example%d", i) {
t.Fatalf("%s, want: https://tracker.debian.org/example%d\n", v.(deb).URL, i)
}
}
}