-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathupdater_test.go
42 lines (39 loc) · 862 Bytes
/
updater_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
package selfupdate
import (
"strings"
"testing"
)
func TestCompileRegexForFiltering(t *testing.T) {
filters := []string{
"^hello$",
"^(\\d\\.)+\\d$",
}
up, err := NewUpdater(Config{
Filters: filters,
})
if err != nil {
t.Fatal(err)
}
if len(up.filters) != 2 {
t.Fatalf("Wanted 2 regexes but got %d", len(up.filters))
}
for i, r := range up.filters {
want := filters[i]
got := r.String()
if want != got {
t.Errorf("Compiled regex is %q but specified was %q", got, want)
}
}
}
func TestFilterRegexIsBroken(t *testing.T) {
_, err := NewUpdater(Config{
Filters: []string{"(foo"},
})
if err == nil {
t.Fatal("Error unexpectedly did not occur")
}
msg := err.Error()
if !strings.Contains(msg, "could not compile regular expression \"(foo\" for filtering releases") {
t.Fatalf("Error message is unexpected: %q", msg)
}
}