Skip to content

Commit

Permalink
Merge pull request #149 from caarlos0/fix-header
Browse files Browse the repository at this point in the history
fix: panic whith custom http headers
  • Loading branch information
wjdp committed Aug 12, 2020
2 parents 5f77419 + 29e91ca commit 6297c3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 6 additions & 5 deletions htmltest/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package htmltest

import (
"fmt"
"github.com/imdario/mergo"
"github.com/wjdp/htmltest/issues"
"path"
"reflect"
"regexp"
"strings"

"github.com/imdario/mergo"
"github.com/wjdp/htmltest/issues"
)

// Options struct for htmltest, user and default options are merged and mapped
Expand Down Expand Up @@ -113,7 +114,7 @@ func DefaultOptions() map[string]interface{} {
"IgnoreSSLVerify": false,
"IgnoreTagAttribute": "data-proofer-ignore",

"HTTPHeaders": map[string]string{
"HTTPHeaders": map[interface{}]interface{}{
"Range": "bytes=0-0", // If server supports prevents body being sent
"Accept": "*/*", // We accept all content types
},
Expand Down Expand Up @@ -145,9 +146,9 @@ func DefaultOptions() map[string]interface{} {
func (hT *HTMLTest) setOptions(optsUser map[string]interface{}) {
// Merge user and default options, set Opts var
optsMap := DefaultOptions()
mergo.MergeWithOverwrite(&optsMap, optsUser)
mergo.Merge(&optsMap, optsUser, mergo.WithOverride)
hT.opts = Options{}
mergo.MapWithOverwrite(&hT.opts, optsMap)
mergo.Map(&hT.opts, optsMap, mergo.WithOverride)

// If debug dump the options struct
if hT.opts.LogLevel == issues.LevelDebug {
Expand Down
18 changes: 17 additions & 1 deletion htmltest/options_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package htmltest

import (
"testing"

"github.com/daviddengcn/go-assert"
"github.com/wjdp/htmltest/output"
"testing"
)

func TestDefaultOptions(t *testing.T) {
Expand Down Expand Up @@ -57,3 +58,18 @@ func TestIsURLIgnored(t *testing.T) {
assert.IsFalse(t, "url left alone", hT.opts.isURLIgnored("https://froogle.com/?q=1234"))
assert.IsFalse(t, "url left alone", hT.opts.isURLIgnored("http://assetstore.info/lib/test.js"))
}

func TestMergeHTTPHeaders(t *testing.T) {
userOpts := map[string]interface{}{
"HTTPHeaders": map[interface{}]interface{}{
"Range": "bytes=0-10",
"Accept": "*/*",
},
"NoRun": true,
}

hT, err := Test(userOpts)
output.CheckErrorPanic(err)

assert.Equals(t, "url ignored", hT.opts.HTTPHeaders["Range"], "bytes=0-10")
}

0 comments on commit 6297c3b

Please sign in to comment.