config: Improve the Provider matching to have a negated match #2140

This makes it easier to make classes of provider in the config.
This commit is contained in:
Nick Craig-Wood
2018-04-13 16:06:37 +01:00
parent acd5d4377e
commit 8c3740c2c5
3 changed files with 70 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
package config
import (
"fmt"
"io/ioutil"
"os"
"testing"
@@ -205,3 +206,24 @@ func hashedKeyCompare(t *testing.T, a, b string, shouldMatch bool) {
assert.NotEqual(t, k1, k2)
}
}
func TestMatchProvider(t *testing.T) {
for _, test := range []struct {
config string
provider string
want bool
}{
{"", "", true},
{"one", "one", true},
{"one,two", "two", true},
{"one,two,three", "two", true},
{"one", "on", false},
{"one,two,three", "tw", false},
{"!one,two,three", "two", false},
{"!one,two,three", "four", true},
} {
what := fmt.Sprintf("%q,%q", test.config, test.provider)
got := matchProvider(test.config, test.provider)
assert.Equal(t, test.want, got, what)
}
}