Skip to content

Commit

Permalink
Add safety check for nil config (#46)
Browse files Browse the repository at this point in the history
When there's no config defined the HTTP header check for defaults panics.
  • Loading branch information
rafaeljusto authored and sjkaliski committed Aug 23, 2018
1 parent 1966219 commit 21d0250
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ func assertHTTP(t *testing.T, id string, body []byte, isJSON bool) {
data := string(body)
lines := strings.Split(strings.TrimSpace(data), "\n")

// empty line identifies the end of the HTTP header
for i, line := range lines {
if line == "" {
break
}
if config != nil {
// empty line identifies the end of the HTTP header
for i, line := range lines {
if line == "" {
break
}

headerItem := strings.Split(line, ":")
if def, ok := config.Defaults[headerItem[0]]; ok {
lines[i] = fmt.Sprintf("%s: %s", headerItem[0], def)
headerItem := strings.Split(line, ":")
if def, ok := config.Defaults[headerItem[0]]; ok {
lines[i] = fmt.Sprintf("%s: %s", headerItem[0], def)
}
}
}

Expand Down

0 comments on commit 21d0250

Please sign in to comment.