mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Unit test the parsing of -header arguments
Per the features described in the preceding commit.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package replay
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -69,3 +71,41 @@ func TestElasticSearchSettings(t *testing.T) {
|
||||
t.Error("Index not match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdditionalHeaders(t *testing.T) {
|
||||
args := []string{
|
||||
"-header", "Empty:",
|
||||
"-header", "Foo: contains:multiple:colons",
|
||||
"-header", "Host:nospaces.example.com",
|
||||
"-header", "Authorization: Basic Zm9vOmJhcg==",
|
||||
"-header", " User-Agent : Contains leading and trailing space ",
|
||||
}
|
||||
out := Headers{
|
||||
{"Empty", ""},
|
||||
{"Foo", "contains:multiple:colons"},
|
||||
{"Host", "nospaces.example.com"},
|
||||
{"Authorization", "Basic Zm9vOmJhcg=="},
|
||||
{"User-Agent", "Contains leading and trailing space"},
|
||||
}
|
||||
|
||||
headers := Headers{}
|
||||
fs := flag.NewFlagSet("TestHeaders", flag.ExitOnError)
|
||||
fs.Var(&headers, "header", "blah")
|
||||
fs.Parse(args)
|
||||
|
||||
if !reflect.DeepEqual(headers, out) {
|
||||
t.Error("Headers not parsed as expected")
|
||||
}
|
||||
|
||||
args = []string{
|
||||
"-header", "contains no colons",
|
||||
}
|
||||
headers = Headers{}
|
||||
fs = flag.NewFlagSet("TestHeaders", flag.ContinueOnError)
|
||||
fs.Var(&headers, "header", "blah")
|
||||
err := fs.Parse(args)
|
||||
|
||||
if err == nil {
|
||||
t.Error("Invalid header should be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user