@@ -108,13 +108,26 @@ func TestRouteServePOST201WithParams(t *testing.T) {
108
108
assert .Equal (t , "true" , r .QP ["param2" ])
109
109
assert .Equal (t , "false" , r .QP ["param3" ])
110
110
assert .Equal (t , []string {"x" , "y" }, r .QAP ["param4" ])
111
+ assert .Equal (t , "12345" , r .Req .Context ().Value (CtxFFRequestIDKey {}).(string ))
112
+ assert .Equal (t , "custom-value" , r .Req .Context ().Value (CtxHeadersKey {}).(http.Header ).Get ("X-Custom-Header" ))
111
113
return map [string ]interface {}{"output1" : "value2" }, nil
112
114
},
113
115
}}, "" , nil )
114
116
defer done ()
117
+ SetRequestIDHeader ("x-unittest-req-id" ) // tests custom req header
118
+ defer func () {
119
+ SetRequestIDHeader (DefaultRequestIDHeader ) // reverts this for other tests
120
+ }()
115
121
116
122
b , _ := json .Marshal (map [string ]interface {}{"input1" : "value1" })
117
- res , err := http .Post (fmt .Sprintf ("http://%s/test/stuff?param1=thing¶m2¶m3=false¶m4=x¶m4=y" , s .Addr ()), "application/json" , bytes .NewReader (b ))
123
+
124
+ req , err := http .NewRequest (http .MethodPost , fmt .Sprintf ("http://%s/test/stuff?param1=thing¶m2¶m3=false¶m4=x¶m4=y" , s .Addr ()), bytes .NewReader (b ))
125
+ require .NoError (t , err )
126
+ req .Header .Set ("Content-Type" , "application/json" )
127
+ req .Header .Set ("X-Custom-Header" , "custom-value" ) // tests custom header
128
+ req .Header .Set ("x-unittest-req-id" , "12345" ) // tests custom req header
129
+
130
+ res , err := http .DefaultClient .Do (req )
118
131
assert .NoError (t , err )
119
132
assert .Equal (t , 201 , res .StatusCode )
120
133
var resJSON map [string ]interface {}
@@ -134,13 +147,19 @@ func TestRouteServePOST201WithParamsLargeNumber(t *testing.T) {
134
147
JSONOutputCodes : []int {201 },
135
148
JSONHandler : func (r * APIRequest ) (output interface {}, err error ) {
136
149
assert .Equal (t , r .Input , map [string ]interface {}{"largeNumberParam" : json .Number ("10000000000000000000000000001" )})
150
+ assert .Equal (t , "12345" , r .Req .Context ().Value (CtxFFRequestIDKey {}).(string ))
137
151
// Echo the input back as the response
138
152
return r .Input , nil
139
153
},
140
154
}}, "" , nil )
141
155
defer done ()
142
156
143
- res , err := http .Post (fmt .Sprintf ("http://%s/test/stuff" , s .Addr ()), "application/json" , bytes .NewReader ([]byte (largeParamLiteral )))
157
+ req , err := http .NewRequest (http .MethodPost , fmt .Sprintf ("http://%s/test/stuff" , s .Addr ()), bytes .NewReader ([]byte (largeParamLiteral )))
158
+ require .NoError (t , err )
159
+ req .Header .Set ("Content-Type" , "application/json" )
160
+ req .Header .Set (DefaultRequestIDHeader , "12345" ) // tests client setting req header
161
+
162
+ res , err := http .DefaultClient .Do (req )
144
163
assert .NoError (t , err )
145
164
assert .Equal (t , 201 , res .StatusCode )
146
165
var resJSON map [string ]interface {}
0 commit comments