Skip to content

Commit

Permalink
Fix K6_BLOCK_HOSTNAMES val getting overwritten.
Browse files Browse the repository at this point in the history
  • Loading branch information
krashanoff committed Jul 3, 2020
1 parent 9dee57f commit 9b59100
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ func getOptions(flags *pflag.FlagSet) (lib.Options, error) {
if err != nil {
return opts, err
}
opts.BlockedHostnames = &lib.HostnameTrie{}
if len(blockedHostnameStrings) > 0 {
opts.BlockedHostnames = &lib.HostnameTrie{}
}
for _, s := range blockedHostnameStrings {
if insertErr := opts.BlockedHostnames.Insert(s); insertErr != nil {
return opts, errors.Wrap(insertErr, "block-hostname")
Expand Down
11 changes: 9 additions & 2 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net"
"reflect"
"regexp"
"strings"

"github.com/loadimpact/k6/lib/scheduler"
"github.com/loadimpact/k6/lib/types"
Expand Down Expand Up @@ -226,9 +227,15 @@ func (t *HostnameTrie) UnmarshalJSON(data []byte) error {
return nil
}

// UnmarshalText forms a HostnameTrie from a given hostname pattern.
// UnmarshalText forms a HostnameTrie from a comma-delimited list
// of hostname patterns.
func (t *HostnameTrie) UnmarshalText(b []byte) error {
return t.Insert(string(b))
for _, s := range strings.Split(string(b), ",") {
if err := t.Insert(s); err != nil {
return err
}
}
return nil
}

// Insert a string into the given HostnameTrie.
Expand Down

0 comments on commit 9b59100

Please sign in to comment.