-
Notifications
You must be signed in to change notification settings - Fork 16
/
main_test.go
76 lines (67 loc) · 1.51 KB
/
main_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
package main
import (
"strings"
"testing"
"github.com/PuerkitoBio/goquery"
)
func TestGetFileAndPath(t *testing.T) {
args := map[string]map[string]string{
"bin/file": {
"file": "file*",
"path": "*bin",
},
"posix": {
"file": "*posix*",
"path": "",
},
"/usr/bin/bash": {
"file": "bash*",
"path": "*/usr/bin",
},
}
for input, output := range args {
f, p := getFileAndPath(input)
if output["file"] != f {
t.Fatalf("expected %q, got %q", output["file"], f)
}
if output["path"] != p {
t.Fatalf("expected %q, got %q", output["path"], p)
}
}
}
func TestParseHTML(t *testing.T) {
searchResults := `
<table class="pure-table table-striped table-bordered table-condensed" data-toggle="table">
<tbody>
<tr>
<th>File</th>
<th>Package</th>
<th>Branch</th>
<th>Repository</th>
<th>Architecture</th>
</tr>
<tr>
<td>/usr/lib/php7/modules/posix.so</td>
<td><a href="/package/edge/testing/armhf/php7-posix">php7-posix</a></td>
<td>edge</td>
<td>testing</td>
<td>armhf</td>
</tr>
</tbody>
</table>
`
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(searchResults))
files := getFilesInfo(doc)
if len(files) != 1 {
t.Fatalf("expected %d, got %d", 1, len(files))
}
expectedFile := fileInfo{
path: "/usr/lib/php7/modules/posix.so",
pkg: "php7-posix",
branch: "edge",
repo: "testing",
arch: "armhf"}
if files[0] != expectedFile {
t.Fatalf("expected %v, got %v", expectedFile, files[0])
}
}