Repository navigation
Expand file tree
/
Copy pathheaders_test.go
More file actions
85 lines (79 loc) · 1.69 KB
/
Copy pathheaders_test.go
File metadata and controls
85 lines (79 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package hx
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResponse(t *testing.T) {
t.Parallel()
type args struct {
options []HeaderOption
}
tests := map[string]struct {
args args
wantHeaders http.Header
wantErr error
}{
"Set headers": {
args: args{
options: []HeaderOption{
Location("/foo"),
SwapOuterHtml.FocusScroll(true),
},
},
wantHeaders: http.Header{
HxLocation: []string{`/foo`},
HxReswap: []string{`outerHTML focusScroll:true`},
},
},
"Overwrite headers": {
args: args{
options: []HeaderOption{
Location("/foo"),
SwapOuterHtml.FocusScroll(true),
Location("/bar"),
},
},
wantHeaders: http.Header{
HxLocation: []string{`/bar`},
HxReswap: []string{`outerHTML focusScroll:true`},
},
},
"Set status and headers": {
args: args{
options: []HeaderOption{
Location("/foo"),
SwapOuterHtml.FocusScroll(false),
},
},
wantHeaders: http.Header{
HxLocation: []string{`/foo`},
HxReswap: []string{`outerHTML focusScroll:false`},
},
},
//"Panics and recovers": {
// args: args{
// options: []HeaderOption{
// Location("/foo"),
// Trigger(func() map[string]any {
// panic(fmt.Errorf("bad event data"))
// }),
// },
// },
// wantErr: fmt.Errorf("bad event data"),
//},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
wr := httptest.NewRecorder()
err := Headers(wr, tt.args.options...)
if tt.wantErr != nil {
assert.EqualError(t, err, tt.wantErr.Error())
return
}
gotHeaders := wr.Header()
assert.Equal(t, tt.wantHeaders, gotHeaders)
})
}
}