add tests for initializing filter regexes
This commit is contained in:
parent
351a78b1eb
commit
a4d48e7891
|
@ -2,6 +2,7 @@ package selfupdate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,3 +68,39 @@ func TestGitHubEnterpriseClientInvalidURL(t *testing.T) {
|
||||||
t.Fatal("Invalid URL should raise an error")
|
t.Fatal("Invalid URL should raise an error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue