diff --git a/cmd/options.go b/cmd/options.go index 480bcfd2346..61921b6bee4 100644 --- a/cmd/options.go +++ b/cmd/options.go @@ -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") diff --git a/lib/options.go b/lib/options.go index 0fa187fcfdf..09e45556a4b 100644 --- a/lib/options.go +++ b/lib/options.go @@ -27,6 +27,7 @@ import ( "net" "reflect" "regexp" + "strings" "github.com/loadimpact/k6/lib/scheduler" "github.com/loadimpact/k6/lib/types" @@ -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.