-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
response_fluent_request_test.go
101 lines (95 loc) · 2.89 KB
/
response_fluent_request_test.go
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package fastshot
import (
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResponseFluentRequest(t *testing.T) {
tests := []struct {
name string
request *http.Request
expectedMethod string
expectedURL string
expectedHeader http.Header
}{
{
name: "GET request",
request: &http.Request{
Method: "GET",
URL: &url.URL{Scheme: "https", Host: "api.example.com", Path: "/users"},
Header: http.Header{"Accept": []string{"application/json"}},
},
expectedMethod: "GET",
expectedURL: "https://api.example.com/users",
expectedHeader: http.Header{"Accept": []string{"application/json"}},
},
{
name: "POST request with query parameters",
request: &http.Request{
Method: "POST",
URL: &url.URL{Scheme: "https", Host: "api.example.com", Path: "/users", RawQuery: "page=1&limit=10"},
Header: http.Header{"Content-Type": []string{"application/json"}},
},
expectedMethod: "POST",
expectedURL: "https://api.example.com/users?page=1&limit=10",
expectedHeader: http.Header{"Content-Type": []string{"application/json"}},
},
{
name: "PUT request with multiple headers",
request: &http.Request{
Method: "PUT",
URL: &url.URL{Scheme: "https", Host: "api.example.com", Path: "/users/123"},
Header: http.Header{
"Content-Type": []string{"application/json"},
"Authorization": []string{"Bearer token123"},
},
},
expectedMethod: "PUT",
expectedURL: "https://api.example.com/users/123",
expectedHeader: http.Header{
"Content-Type": []string{"application/json"},
"Authorization": []string{"Bearer token123"},
},
},
{
name: "DELETE request with no headers",
request: &http.Request{
Method: "DELETE",
URL: &url.URL{Scheme: "https", Host: "api.example.com", Path: "/users/123"},
Header: http.Header{},
},
expectedMethod: "DELETE",
expectedURL: "https://api.example.com/users/123",
expectedHeader: http.Header{},
},
{
name: "PATCH request with fragment",
request: &http.Request{
Method: "PATCH",
URL: &url.URL{Scheme: "https", Host: "api.example.com", Path: "/users/123", Fragment: "section1"},
Header: http.Header{"Content-Type": []string{"application/json-patch+json"}},
},
expectedMethod: "PATCH",
expectedURL: "https://api.example.com/users/123#section1",
expectedHeader: http.Header{"Content-Type": []string{"application/json-patch+json"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Arrange
response := &Response{
request: &ResponseFluentRequest{
request: tt.request,
},
}
// Act
result := response.Request()
// Assert
assert.Equal(t, tt.request, result.Raw())
assert.Equal(t, tt.expectedMethod, result.Method())
assert.Equal(t, tt.expectedURL, result.URL())
assert.Equal(t, tt.expectedHeader, result.Headers())
})
}
}