Skip to content

Commit

Permalink
various readability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyll committed Aug 19, 2017
1 parent 7f5f712 commit 5567391
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 1 addition & 2 deletions hey.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ var (
q = flag.Int("q", 0, "")
t = flag.Int("t", 20, "")

h2 = flag.Bool("h2", false, "")

h2 = flag.Bool("h2", false, "")
cpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "")

disableCompression = flag.Bool("disable-compression", false, "")
Expand Down
24 changes: 15 additions & 9 deletions hey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,46 @@ import (
func TestParseValidHeaderFlag(t *testing.T) {
match, err := parseInputWithRegexp("X-Something: !Y10K:;(He@poverflow?)", headerRegexp)
if err != nil {
t.Errorf("A valid header was not parsed correctly: %v", err.Error())
t.Errorf("parseInputWithRegexp errored: %v", err)
}
if match[1] != "X-Something" || match[2] != "!Y10K:;(He@poverflow?)" {
t.Errorf("A valid header was not parsed correctly, parsed values: %v %v", match[1], match[2])
if got, want := match[1], "X-Something"; got != want {
t.Errorf("got %v; want %v", got, want)
}
if got, want := match[2], "!Y10K:;(He@poverflow?)"; got != want {
t.Errorf("got %v; want %v", got, want)
}
}

func TestParseInvalidHeaderFlag(t *testing.T) {
_, err := parseInputWithRegexp("X|oh|bad-input: badbadbad", headerRegexp)
if err == nil {
t.Errorf("An invalid header passed parsing")
t.Errorf("Header parsing errored; want no errors")
}
}

func TestParseValidAuthFlag(t *testing.T) {
match, err := parseInputWithRegexp("_coo-kie_:!!bigmonster@1969sid", authRegexp)
if err != nil {
t.Errorf("A valid auth flag was not parsed correctly: %v", err.Error())
t.Errorf("A valid auth flag was not parsed correctly: %v", err)
}
if got, want := match[1], "_coo-kie_"; got != want {
t.Errorf("got %v; want %v", got, want)
}
if match[1] != "_coo-kie_" || match[2] != "!!bigmonster@1969sid" {
t.Errorf("A valid auth flag was not parsed correctly, parsed values: %v %v", match[1], match[2])
if got, want := match[2], "!!bigmonster@1969sid"; got != want {
t.Errorf("got %v; want %v", got, want)
}
}

func TestParseInvalidAuthFlag(t *testing.T) {
_, err := parseInputWithRegexp("X|oh|bad-input: badbadbad", authRegexp)
if err == nil {
t.Errorf("An invalid header passed parsing")
t.Errorf("Header parsing errored; want no errors")
}
}

func TestParseAuthMetaCharacters(t *testing.T) {
_, err := parseInputWithRegexp("plus+$*{:boom", authRegexp)
if err != nil {
t.Errorf("Could not parse an auth header with a plus sign in the user name")
t.Errorf("Auth header with a plus sign in the user name errored: %v", err)
}
}

0 comments on commit 5567391

Please sign in to comment.