Skip to content

Commit 5e33c96

Browse files
committed
Added parse tests
1 parent 828c770 commit 5e33c96

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

response/parse_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// response/parse_test.go
2+
package response
3+
4+
import (
5+
"reflect"
6+
"testing"
7+
)
8+
9+
func TestParseContentTypeHeader(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
header string
13+
wantType string
14+
wantParams map[string]string
15+
}{
16+
{
17+
name: "Basic",
18+
header: "text/html; charset=UTF-8",
19+
wantType: "text/html",
20+
wantParams: map[string]string{"charset": "UTF-8"},
21+
},
22+
{
23+
name: "No Params",
24+
header: "application/json",
25+
wantType: "application/json",
26+
wantParams: map[string]string{},
27+
},
28+
{
29+
name: "Multiple Params",
30+
header: "multipart/form-data; boundary=something; charset=utf-8",
31+
wantType: "multipart/form-data",
32+
wantParams: map[string]string{"boundary": "something", "charset": "utf-8"},
33+
},
34+
}
35+
36+
for _, tt := range tests {
37+
t.Run(tt.name, func(t *testing.T) {
38+
gotType, gotParams := ParseContentTypeHeader(tt.header)
39+
if gotType != tt.wantType {
40+
t.Errorf("ParseContentTypeHeader() gotType = %v, want %v", gotType, tt.wantType)
41+
}
42+
if !reflect.DeepEqual(gotParams, tt.wantParams) {
43+
t.Errorf("ParseContentTypeHeader() gotParams = %v, want %v", gotParams, tt.wantParams)
44+
}
45+
})
46+
}
47+
}
48+
49+
func TestParseContentDisposition(t *testing.T) {
50+
tests := []struct {
51+
name string
52+
header string
53+
wantType string
54+
wantParams map[string]string
55+
}{
56+
{
57+
name: "Attachment with Filename",
58+
header: "attachment; filename=\"filename.jpg\"",
59+
wantType: "attachment",
60+
wantParams: map[string]string{"filename": "filename.jpg"},
61+
},
62+
{
63+
name: "Inline",
64+
header: "inline",
65+
wantType: "inline",
66+
wantParams: map[string]string{},
67+
},
68+
// Add more test cases as needed
69+
}
70+
71+
for _, tt := range tests {
72+
t.Run(tt.name, func(t *testing.T) {
73+
gotType, gotParams := ParseContentDisposition(tt.header)
74+
if gotType != tt.wantType {
75+
t.Errorf("ParseContentDisposition() gotType = %v, want %v", gotType, tt.wantType)
76+
}
77+
if !reflect.DeepEqual(gotParams, tt.wantParams) {
78+
t.Errorf("ParseContentDisposition() gotParams = %v, want %v", gotParams, tt.wantParams)
79+
}
80+
})
81+
}
82+
}

0 commit comments

Comments
 (0)