@@ -190,7 +190,9 @@ func Test_splunkhecReceiver_handleReq(t *testing.T) {
190
190
{
191
191
name : "incorrect_content_type" ,
192
192
req : func () * http.Request {
193
- req := httptest .NewRequest ("POST" , "http://localhost/foo" , nil )
193
+ msgBytes , err := json .Marshal (splunkMsg )
194
+ require .NoError (t , err )
195
+ req := httptest .NewRequest ("POST" , "http://localhost/foo" , bytes .NewReader (msgBytes ))
194
196
req .Header .Set ("Content-Type" , "application/not-json" )
195
197
return req
196
198
}(),
@@ -234,7 +236,7 @@ func Test_splunkhecReceiver_handleReq(t *testing.T) {
234
236
}(),
235
237
assertResponse : func (t * testing.T , status int , body string ) {
236
238
assert .Equal (t , http .StatusBadRequest , status )
237
- assert .Equal (t , responseErrUnmarshalBody , body )
239
+ assert .Equal (t , responseInvalidDataFormat , body )
238
240
},
239
241
},
240
242
{
@@ -244,8 +246,51 @@ func Test_splunkhecReceiver_handleReq(t *testing.T) {
244
246
return req
245
247
}(),
246
248
assertResponse : func (t * testing.T , status int , body string ) {
247
- assert .Equal (t , http .StatusOK , status )
248
- assert .Equal (t , responseOK , body )
249
+ assert .Equal (t , http .StatusBadRequest , status )
250
+ assert .Equal (t , responseNoData , body )
251
+ },
252
+ },
253
+ {
254
+ name : "invalid_data_format" ,
255
+ req : func () * http.Request {
256
+ msgBytes , err := json .Marshal (`{"foo":"bar"}` )
257
+ require .NoError (t , err )
258
+ req := httptest .NewRequest ("POST" , "http://localhost/foo" , bytes .NewReader (msgBytes ))
259
+ return req
260
+ }(),
261
+ assertResponse : func (t * testing.T , status int , body string ) {
262
+ assert .Equal (t , http .StatusBadRequest , status )
263
+ assert .Equal (t , responseInvalidDataFormat , body )
264
+ },
265
+ },
266
+ {
267
+ name : "event_required_error" ,
268
+ req : func () * http.Request {
269
+ nilEventMsg := buildSplunkHecMsg (currentTime , 3 )
270
+ nilEventMsg .Event = nil
271
+ msgBytes , err := json .Marshal (nilEventMsg )
272
+ require .NoError (t , err )
273
+ req := httptest .NewRequest ("POST" , "http://localhost/foo" , bytes .NewReader (msgBytes ))
274
+ return req
275
+ }(),
276
+ assertResponse : func (t * testing.T , status int , body string ) {
277
+ assert .Equal (t , http .StatusBadRequest , status )
278
+ assert .Equal (t , responseErrEventRequired , body )
279
+ },
280
+ },
281
+ {
282
+ name : "event_cannot_be_blank_error" ,
283
+ req : func () * http.Request {
284
+ blankEventMsg := buildSplunkHecMsg (currentTime , 3 )
285
+ blankEventMsg .Event = ""
286
+ msgBytes , err := json .Marshal (blankEventMsg )
287
+ require .NoError (t , err )
288
+ req := httptest .NewRequest ("POST" , "http://localhost/foo" , bytes .NewReader (msgBytes ))
289
+ return req
290
+ }(),
291
+ assertResponse : func (t * testing.T , status int , body string ) {
292
+ assert .Equal (t , http .StatusBadRequest , status )
293
+ assert .Equal (t , responseErrEventBlank , body )
249
294
},
250
295
},
251
296
{
@@ -864,7 +909,7 @@ func Test_splunkhecReceiver_handleRawReq(t *testing.T) {
864
909
{
865
910
name : "incorrect_content_type" ,
866
911
req : func () * http.Request {
867
- req := httptest .NewRequest ("POST" , "http://localhost/foo" , nil )
912
+ req := httptest .NewRequest ("POST" , "http://localhost/foo" , strings . NewReader ( "foo \n bar" ) )
868
913
req .Header .Set ("Content-Type" , "application/not-json" )
869
914
return req
870
915
}(),
@@ -891,7 +936,8 @@ func Test_splunkhecReceiver_handleRawReq(t *testing.T) {
891
936
return req
892
937
}(),
893
938
assertResponse : func (t * testing.T , status int , body string ) {
894
- assert .Equal (t , http .StatusOK , status )
939
+ assert .Equal (t , http .StatusBadRequest , status )
940
+ assert .Equal (t , responseNoData , body )
895
941
},
896
942
},
897
943
0 commit comments