@@ -341,99 +341,3 @@ func TestInitialisationFromENV(t *testing.T) {
341
341
expectedClient := & Client {Key : "feaf18a411d3cb9216ee" , Secret : "fec81108d90e1898e17a" , AppId : "104060" , Host : "api.pusherapp.com" }
342
342
assert .Equal (t , expectedClient , client )
343
343
}
344
-
345
- func TestNotifySuccess (t * testing.T ) {
346
- server := httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
347
- res .WriteHeader (http .StatusOK )
348
- res .Write ([]byte (`{"number_of_subscribers": 10}` ))
349
- }))
350
- defer server .Close ()
351
-
352
- u , _ := url .Parse (server .URL )
353
- client := Client {AppId : "id" , Key : "key" , Secret : "secret" , PushNotificationHost : u .Host , HttpClient : & http.Client {Timeout : time .Millisecond * 100 }}
354
- testPN := PushNotification {
355
- WebhookURL : "testURL" ,
356
- GCM : []byte (`hello` ),
357
- }
358
- interests := []string {"testInterest" }
359
- response , err := client .Notify (interests , testPN )
360
-
361
- assert .Equal (t , 10 , response .NumSubscribers , "returned response.NumSubscribers should be equal to the server response body amount" )
362
- assert .NoError (t , err )
363
- }
364
-
365
- func TestNotifySuccessNoSubscribers (t * testing.T ) {
366
- server := httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
367
- res .WriteHeader (http .StatusAccepted )
368
- res .Write ([]byte (`{"number_of_subscribers":0}` ))
369
- }))
370
- defer server .Close ()
371
-
372
- u , _ := url .Parse (server .URL )
373
- client := Client {AppId : "id" , Key : "key" , Secret : "secret" , PushNotificationHost : u .Host , HttpClient : & http.Client {Timeout : time .Millisecond * 100 }}
374
- testPN := PushNotification {
375
- WebhookURL : "testURL" ,
376
- GCM : []byte (`hello` ),
377
- }
378
- interests := []string {"testInterest" }
379
- response , err := client .Notify (interests , testPN )
380
-
381
- assert .Equal (t , 0 , response .NumSubscribers , "returned response.NumSubscribers should be equal to the server response body amount" )
382
- assert .NoError (t , err )
383
- }
384
-
385
- func TestNotifyServerError (t * testing.T ) {
386
- server := httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
387
- res .WriteHeader (http .StatusInternalServerError )
388
- }))
389
- defer server .Close ()
390
-
391
- u , _ := url .Parse (server .URL )
392
- client := Client {AppId : "id" , Key : "key" , Secret : "secret" , PushNotificationHost : u .Host , HttpClient : & http.Client {Timeout : time .Millisecond * 100 }}
393
- testPN := PushNotification {
394
- WebhookURL : "testURL" ,
395
- GCM : []byte (`hello` ),
396
- }
397
-
398
- interests := []string {"testInterest" }
399
- response , err := client .Notify (interests , testPN )
400
-
401
- assert .Nil (t , response , "response should return nil on error" )
402
- assert .Error (t , err )
403
- assert .EqualError (t , err , "Status Code: 500 - " )
404
- }
405
-
406
- func TestNotifyInvalidPushNotification (t * testing.T ) {
407
- server := httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
408
- res .WriteHeader (http .StatusInternalServerError )
409
- }))
410
- defer server .Close ()
411
-
412
- u , _ := url .Parse (server .URL )
413
- client := Client {AppId : "id" , Key : "key" , Secret : "secret" , PushNotificationHost : u .Host , HttpClient : & http.Client {Timeout : time .Millisecond * 100 }}
414
- testPN := PushNotification {
415
- WebhookURL : "testURL" ,
416
- }
417
- interests := []string {"testInterest" }
418
- response , err := client .Notify (interests , testPN )
419
-
420
- assert .Nil (t , response , "response should return nil on error" )
421
- assert .Error (t , err )
422
- }
423
-
424
- func TestNotifyNoPushNotificationHost (t * testing.T ) {
425
- server := httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
426
- res .WriteHeader (http .StatusInternalServerError )
427
- }))
428
- defer server .Close ()
429
-
430
- client := Client {AppId : "id" , Key : "key" , Secret : "secret" , HttpClient : & http.Client {Timeout : time .Millisecond * 100 }}
431
- testPN := PushNotification {
432
- WebhookURL : "testURL" ,
433
- }
434
- interests := []string {"testInterest" }
435
- response , err := client .Notify (interests , testPN )
436
-
437
- assert .Nil (t , response , "response should return nil on error" )
438
- assert .Error (t , err )
439
- }
0 commit comments