@@ -381,3 +381,104 @@ func TestGetAlert(t *testing.T) {
381
381
t .Errorf ("Wrong data for alert: %v" , alert )
382
382
}
383
383
}
384
+
385
+ func TestFindAlertLogs (t * testing.T ) {
386
+ ts := httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
387
+ url := fmt .Sprintf ("/api/v0/alerts/%s/logs" , "2wpLU5fBXbG" )
388
+ if req .URL .Path != url {
389
+ t .Error ("request URL should be /api/v0/alerts/<ID>/logs but: " , req .URL .Path )
390
+ }
391
+
392
+ if req .Method != "GET" {
393
+ t .Error ("request method should be GET but: " , req .Method )
394
+ }
395
+
396
+ respJSON , _ := json .Marshal (map [string ]interface {}{
397
+ "logs" : []map [string ]interface {}{
398
+ {
399
+ "id" : "5m7fewuu5tS" ,
400
+ "createdAt" : 1735290407 ,
401
+ "status" : "WARNING" ,
402
+ "trigger" : "monitoring" ,
403
+ "monitorId" : "5m72DB7s7sU" ,
404
+ "targetValue" : (* float64 )(nil ),
405
+ "statusDetail" : map [string ]interface {}{
406
+ "type" : "check" ,
407
+ "detail" : map [string ]interface {}{
408
+ "message" : "Uptime WARNING: 0 day(s) 0 hour(s) 6 minute(s) (398 second(s))" ,
409
+ "memo" : "" ,
410
+ },
411
+ },
412
+ }, {
413
+ "id" : "5m7fewuu5tS" ,
414
+ "createdAt" : 1735290407 ,
415
+ "status" : "WARNING" ,
416
+ "trigger" : "monitoring" ,
417
+ "monitorId" : "5m72DB7s7sU" ,
418
+ "targetValue" : (* float64 )(nil ),
419
+ "statusDetail" : nil ,
420
+ },
421
+ },
422
+ "nextId" : "2fsf8jRxFG1" ,
423
+ })
424
+
425
+ res .Header ()["Content-Type" ] = []string {"application/json" }
426
+ fmt .Fprint (res , string (respJSON ))
427
+ }))
428
+ defer ts .Close ()
429
+
430
+ client , _ := NewClientWithOptions ("dummy-key" , ts .URL , false )
431
+ logs , err := client .FindAlertLogs ("2wpLU5fBXbG" )
432
+ if err != nil {
433
+ t .Error ("err should be nil but: " , err )
434
+ }
435
+
436
+ if len (logs .AlertLogs ) != 2 {
437
+ t .Error ("logs should have 1 elements but: " , len (logs .AlertLogs ))
438
+ }
439
+
440
+ if logs .NextID != "2fsf8jRxFG1" {
441
+ t .Error ("request sends json including nextId but: " , logs .NextID )
442
+ }
443
+
444
+ if logs .AlertLogs [0 ].ID != "5m7fewuu5tS" {
445
+ t .Error ("alert id should be \" 5m7fewuu5tS\" but: " , logs .AlertLogs [0 ].ID )
446
+ }
447
+
448
+ if logs .AlertLogs [0 ].CreatedAt != 1735290407 {
449
+ t .Error ("createdAt should be 1735290407 but: " , logs .AlertLogs [0 ].CreatedAt )
450
+ }
451
+
452
+ if logs .AlertLogs [0 ].Trigger != "monitoring" {
453
+ t .Error ("trigger should be \" monitoring\" but: " , logs .AlertLogs [0 ].Trigger )
454
+ }
455
+
456
+ if * logs .AlertLogs [0 ].MonitorID != "5m72DB7s7sU" {
457
+ t .Error ("monitorId should be \" 5m72DB7s7sU\" but: " , * logs .AlertLogs [0 ].MonitorID )
458
+ }
459
+
460
+ if logs .AlertLogs [0 ].TargetValue != nil {
461
+ t .Error ("targetValue should be nil but: " , logs .AlertLogs [0 ].TargetValue )
462
+ }
463
+
464
+ if logs .AlertLogs [0 ].Status != "WARNING" {
465
+ t .Error ("alert status should be \" WARNING\" but: " , logs .AlertLogs [0 ].Status )
466
+ }
467
+
468
+ if logs .AlertLogs [0 ].StatusDetail .Type != "check" {
469
+ t .Error ("statusDetail type should be \" check\" but: " , logs .AlertLogs [0 ].StatusDetail .Type )
470
+ }
471
+
472
+ if logs .AlertLogs [0 ].StatusDetail .Detail .Message != "Uptime WARNING: 0 day(s) 0 hour(s) 6 minute(s) (398 second(s))" {
473
+ t .Error ("statusDetail message should be \" Uptime WARNING: 0 day(s) 0 hour(s) 6 minute(s) (398 second(s))\" but: " , logs .AlertLogs [0 ].StatusDetail .Detail .Message )
474
+ }
475
+
476
+ if logs .AlertLogs [0 ].StatusDetail .Detail .Memo != "" {
477
+ t .Error ("statusDetail memo should be empty but: " , logs .AlertLogs [0 ].StatusDetail .Detail .Memo )
478
+ }
479
+
480
+ if logs .AlertLogs [1 ].StatusDetail != nil {
481
+ t .Error ("statusDetail should be nil but: " , logs .AlertLogs [1 ].StatusDetail )
482
+ }
483
+
484
+ }
0 commit comments