Skip to content

Commit 6297c3b

Browse files
authored
Merge pull request #149 from caarlos0/fix-header
fix: panic whith custom http headers
2 parents 5f77419 + 29e91ca commit 6297c3b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

htmltest/options.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package htmltest
22

33
import (
44
"fmt"
5-
"github.com/imdario/mergo"
6-
"github.com/wjdp/htmltest/issues"
75
"path"
86
"reflect"
97
"regexp"
108
"strings"
9+
10+
"github.com/imdario/mergo"
11+
"github.com/wjdp/htmltest/issues"
1112
)
1213

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

116-
"HTTPHeaders": map[string]string{
117+
"HTTPHeaders": map[interface{}]interface{}{
117118
"Range": "bytes=0-0", // If server supports prevents body being sent
118119
"Accept": "*/*", // We accept all content types
119120
},
@@ -145,9 +146,9 @@ func DefaultOptions() map[string]interface{} {
145146
func (hT *HTMLTest) setOptions(optsUser map[string]interface{}) {
146147
// Merge user and default options, set Opts var
147148
optsMap := DefaultOptions()
148-
mergo.MergeWithOverwrite(&optsMap, optsUser)
149+
mergo.Merge(&optsMap, optsUser, mergo.WithOverride)
149150
hT.opts = Options{}
150-
mergo.MapWithOverwrite(&hT.opts, optsMap)
151+
mergo.Map(&hT.opts, optsMap, mergo.WithOverride)
151152

152153
// If debug dump the options struct
153154
if hT.opts.LogLevel == issues.LevelDebug {

htmltest/options_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package htmltest
22

33
import (
4+
"testing"
5+
46
"github.com/daviddengcn/go-assert"
57
"github.com/wjdp/htmltest/output"
6-
"testing"
78
)
89

910
func TestDefaultOptions(t *testing.T) {
@@ -57,3 +58,18 @@ func TestIsURLIgnored(t *testing.T) {
5758
assert.IsFalse(t, "url left alone", hT.opts.isURLIgnored("https://froogle.com/?q=1234"))
5859
assert.IsFalse(t, "url left alone", hT.opts.isURLIgnored("http://assetstore.info/lib/test.js"))
5960
}
61+
62+
func TestMergeHTTPHeaders(t *testing.T) {
63+
userOpts := map[string]interface{}{
64+
"HTTPHeaders": map[interface{}]interface{}{
65+
"Range": "bytes=0-10",
66+
"Accept": "*/*",
67+
},
68+
"NoRun": true,
69+
}
70+
71+
hT, err := Test(userOpts)
72+
output.CheckErrorPanic(err)
73+
74+
assert.Equals(t, "url ignored", hT.opts.HTTPHeaders["Range"], "bytes=0-10")
75+
}

0 commit comments

Comments
 (0)