github.com/creativeprojects/go-selfupdate@v1.2.0/updater_test.go (about)

     1  package selfupdate
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestCompileRegexForFiltering(t *testing.T) {
     9  	filters := []string{
    10  		"^hello$",
    11  		"^(\\d\\.)+\\d$",
    12  	}
    13  	up, err := NewUpdater(Config{
    14  		Filters: filters,
    15  	})
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  	if len(up.filters) != 2 {
    20  		t.Fatalf("Wanted 2 regexes but got %d", len(up.filters))
    21  	}
    22  	for i, r := range up.filters {
    23  		want := filters[i]
    24  		got := r.String()
    25  		if want != got {
    26  			t.Errorf("Compiled regex is %q but specified was %q", got, want)
    27  		}
    28  	}
    29  }
    30  
    31  func TestFilterRegexIsBroken(t *testing.T) {
    32  	_, err := NewUpdater(Config{
    33  		Filters: []string{"(foo"},
    34  	})
    35  	if err == nil {
    36  		t.Fatal("Error unexpectedly did not occur")
    37  	}
    38  	msg := err.Error()
    39  	if !strings.Contains(msg, "could not compile regular expression \"(foo\" for filtering releases") {
    40  		t.Fatalf("Error message is unexpected: %q", msg)
    41  	}
    42  }