[BUGFIX] config of filter case of one interface at once

This commit is contained in:
Geno 2018-02-15 15:52:14 +01:00
parent 6b522c629c
commit 4473b4fca9
5 changed files with 28 additions and 12 deletions

View File

@ -14,14 +14,18 @@ func init() {
}
func build(config interface{}) (filter.Filter, error) {
values, ok := config.([]string)
values, ok := config.([]interface{})
if !ok {
return nil, errors.New("invalid configuration, array of strings expected")
return nil, errors.New("invalid configuration, array (of strings) expected")
}
list := make(blacklist)
for _, nodeid := range values {
for _, value := range values {
if nodeid, ok := value.(string); ok {
list[nodeid] = struct{}{}
} else {
return nil, errors.New("invalid configuration, array of strings expected")
}
}
return &list, nil
}

View File

@ -15,15 +15,20 @@ func TestFilterBlacklist(t *testing.T) {
filter, err := build(3)
assert.Error(err)
filter, err = build([]interface{}{2, "a"})
assert.Error(err)
// tests with empty list
filter, err = build([]string{})
filter, err = build([]interface{}{})
assert.NoError(err)
// keep node without nodeid
n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
assert.NotNil(n)
// tests with blacklist
filter, _ = build([]string{"a", "c"})
filter, err = build([]interface{}{"a", "c"})
assert.NoError(err)
// blacklist contains node with nodeid -> drop it
n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{NodeID: "a"}})

View File

@ -11,7 +11,7 @@ import (
type noowner struct{ has bool }
func init() {
filter.Register("noowner", build)
filter.Register("no_owner", build)
}
func build(config interface{}) (filter.Filter, error) {

View File

@ -14,14 +14,18 @@ func init() {
}
func build(config interface{}) (filter.Filter, error) {
values, ok := config.([]string)
values, ok := config.([]interface{})
if !ok {
return nil, errors.New("invalid configuration, array of strings expected")
return nil, errors.New("invalid configuration, array (of strings) expected")
}
list := make(sites)
for _, nodeid := range values {
for _, value := range values {
if nodeid, ok := value.(string); ok {
list[nodeid] = struct{}{}
} else {
return nil, errors.New("invalid configuration, array of strings expected")
}
}
return &list, nil
}

View File

@ -15,7 +15,10 @@ func TestFilterSite(t *testing.T) {
filter, err := build("ffhb")
assert.Error(err)
filter, err = build([]string{"ffhb"})
filter, err = build([]interface{}{3, "ffhb"})
assert.Error(err)
filter, err = build([]interface{}{"ffhb"})
assert.NoError(err)
// wronge node