forked from anatol/pacoloco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pacoloco_test.go
69 lines (57 loc) · 1.75 KB
/
pacoloco_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
package main
import (
"io"
"log"
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestMain(m *testing.M) {
if os.Getenv("TEST_VERBOSE") != "1" {
// disable log output
log.SetOutput(io.Discard)
}
os.Exit(m.Run())
}
func TestPathMatcher(t *testing.T) {
pathCheck := func(url string, repoName string, path string, fileName string) {
matches := pathRegex.FindStringSubmatch(url)
if matches == nil {
t.Errorf("url '%v' does not match regexp", url)
}
expected := []string{url, repoName, path, fileName}
if !cmp.Equal(matches, expected) {
t.Errorf("expected '%v' but regexp submatches '%v'", expected, matches)
}
}
pathFails := func(url string) {
matches := pathRegex.FindStringSubmatch(url)
if matches != nil {
t.Errorf("url '%v' expected to fail matching", url)
}
}
pathFails("")
pathFails("/repofoo/webkit2gtk-2.26.4-1-x86_64.pkg.tar.zst")
pathFails("repo/foo/webkit2gtk-2.26.4-1-x86_64.pkg.tar.zst")
pathFails("/repo/webkit2gtk-2.26.4-1-x86_64.pkg.tar.zst")
pathFails("/webkit2gtk/repo/foo/-2.26.4-1-x86_64.pkg.tar.zst")
pathCheck("/repo/foo/webkit2gtk-2.26.4-1-x86_64.pkg.tar.zst", "foo", "", "webkit2gtk-2.26.4-1-x86_64.pkg.tar.zst")
pathCheck("/repo/foo/bar/bazzz/eeee/webkit2x86_64.pkg.tar.zst", "foo", "/bar/bazzz/eeee", "webkit2x86_64.pkg.tar.zst")
}
func TestForceCheckAtServer(t *testing.T) {
forceCheck := func(name string) {
if !forceCheckAtServer(name) {
t.Errorf("File '%v' expected to force check at server", name)
}
}
doNotForceCheck := func(name string) {
if forceCheckAtServer(name) {
t.Errorf("File '%v' expected to not force check at server", name)
}
}
forceCheck("core.db")
forceCheck("core.db.sig")
forceCheck("core.files")
doNotForceCheck("core.1db")
doNotForceCheck("core.db.test")
}