Skip to content

Commit

Permalink
[BUGFIX] config of filter case of one interface at once
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Feb 15, 2018
1 parent 6b522c6 commit 4473b4f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
12 changes: 8 additions & 4 deletions output/filter/blacklist/blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
list[nodeid] = struct{}{}
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
}
Expand Down
9 changes: 7 additions & 2 deletions output/filter/blacklist/blacklist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}})
Expand Down
2 changes: 1 addition & 1 deletion output/filter/noowner/noowner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions output/filter/site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
list[nodeid] = struct{}{}
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
}
Expand Down
5 changes: 4 additions & 1 deletion output/filter/site/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4473b4f

Please sign in to comment.