From 21d02502918aa11978fcb33ec08f9a3f386d45f1 Mon Sep 17 00:00:00 2001 From: Rafael Dantas Justo Date: Thu, 23 Aug 2018 18:20:52 +0100 Subject: [PATCH] Add safety check for nil config (#46) When there's no config defined the HTTP header check for defaults panics. --- assert.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/assert.go b/assert.go index aa18c6f..ab3c637 100644 --- a/assert.go +++ b/assert.go @@ -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) + } } }