[BUGFIX] config of filter case of one interface at once
This commit is contained in:
parent
6b522c629c
commit
4473b4fca9
|
@ -14,14 +14,18 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(config interface{}) (filter.Filter, error) {
|
func build(config interface{}) (filter.Filter, error) {
|
||||||
values, ok := config.([]string)
|
values, ok := config.([]interface{})
|
||||||
if !ok {
|
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)
|
list := make(blacklist)
|
||||||
for _, nodeid := range values {
|
for _, value := range values {
|
||||||
list[nodeid] = struct{}{}
|
if nodeid, ok := value.(string); ok {
|
||||||
|
list[nodeid] = struct{}{}
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("invalid configuration, array of strings expected")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return &list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,15 +15,20 @@ func TestFilterBlacklist(t *testing.T) {
|
||||||
filter, err := build(3)
|
filter, err := build(3)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
|
filter, err = build([]interface{}{2, "a"})
|
||||||
|
assert.Error(err)
|
||||||
|
|
||||||
// tests with empty list
|
// tests with empty list
|
||||||
filter, err = build([]string{})
|
filter, err = build([]interface{}{})
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
// keep node without nodeid
|
// keep node without nodeid
|
||||||
n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
|
n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
|
||||||
assert.NotNil(n)
|
assert.NotNil(n)
|
||||||
|
|
||||||
// tests with blacklist
|
// tests with blacklist
|
||||||
filter, _ = build([]string{"a", "c"})
|
filter, err = build([]interface{}{"a", "c"})
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
// blacklist contains node with nodeid -> drop it
|
// blacklist contains node with nodeid -> drop it
|
||||||
n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{NodeID: "a"}})
|
n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{NodeID: "a"}})
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
type noowner struct{ has bool }
|
type noowner struct{ has bool }
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
filter.Register("noowner", build)
|
filter.Register("no_owner", build)
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(config interface{}) (filter.Filter, error) {
|
func build(config interface{}) (filter.Filter, error) {
|
||||||
|
|
|
@ -14,14 +14,18 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(config interface{}) (filter.Filter, error) {
|
func build(config interface{}) (filter.Filter, error) {
|
||||||
values, ok := config.([]string)
|
values, ok := config.([]interface{})
|
||||||
if !ok {
|
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)
|
list := make(sites)
|
||||||
for _, nodeid := range values {
|
for _, value := range values {
|
||||||
list[nodeid] = struct{}{}
|
if nodeid, ok := value.(string); ok {
|
||||||
|
list[nodeid] = struct{}{}
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("invalid configuration, array of strings expected")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return &list, nil
|
return &list, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,10 @@ func TestFilterSite(t *testing.T) {
|
||||||
filter, err := build("ffhb")
|
filter, err := build("ffhb")
|
||||||
assert.Error(err)
|
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)
|
assert.NoError(err)
|
||||||
|
|
||||||
// wronge node
|
// wronge node
|
||||||
|
|
Loading…
Reference in New Issue