Skip to content

Commit

Permalink
fix: panic whith custom http headers
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Aug 12, 2020
1 parent 5f77419 commit 29e91ca
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 29e91ca

Please sign in to comment.