@@ -957,6 +957,210 @@ func TestDNSMonitorCRUD(t *testing.T) {
957957 })
958958}
959959
960+ func TestICMPMonitorCRUD (t * testing.T ) {
961+ ctx := context .TODO ()
962+
963+ client := setupClient (t )
964+
965+ pendingMonitor := checkly.ICMPMonitor {
966+ Name : "Foo ICMP monitor" ,
967+ Frequency : 1 ,
968+ Request : checkly.ICMPRequest {
969+ Hostname : "welcome.checklyhq.com" ,
970+ IPFamily : "IPv4" ,
971+ PingCount : 5 ,
972+ Assertions : []checkly.Assertion {
973+ {
974+ Source : "LATENCY" ,
975+ Property : "avg" ,
976+ Target : "500" ,
977+ Comparison : "LESS_THAN" ,
978+ },
979+ },
980+ },
981+ Locations : []string {"us-east-1" },
982+ }
983+
984+ createdMonitor , err := client .CreateICMPMonitor (ctx , pendingMonitor )
985+ if err != nil {
986+ t .Fatalf ("failed to create ICMP monitor: %v" , err )
987+ }
988+
989+ var deleteOnce sync.Once
990+ defer func () {
991+ deleteOnce .Do (func () {
992+ _ = client .DeleteICMPMonitor (ctx , createdMonitor .ID )
993+ })
994+ }()
995+
996+ readMonitor , err := client .GetICMPMonitor (ctx , createdMonitor .ID )
997+ if err != nil {
998+ t .Fatalf ("failed to get ICMP monitor: %v" , err )
999+ }
1000+
1001+ if readMonitor .Name != "Foo ICMP monitor" {
1002+ t .Fatalf ("wrong Name after creation" )
1003+ }
1004+
1005+ if readMonitor .Request .Hostname != "welcome.checklyhq.com" {
1006+ t .Fatalf ("wrong Hostname after creation" )
1007+ }
1008+
1009+ if readMonitor .Request .PingCount != 5 {
1010+ t .Fatalf ("wrong PingCount after creation, got %d" , readMonitor .Request .PingCount )
1011+ }
1012+
1013+ if len (readMonitor .Request .Assertions ) != 1 {
1014+ t .Fatalf ("wrong Assertion count after creation" )
1015+ }
1016+
1017+ if readMonitor .Request .Assertions [0 ].Source != "LATENCY" {
1018+ t .Fatalf ("wrong Assertion.Source after creation, got %s" , readMonitor .Request .Assertions [0 ].Source )
1019+ }
1020+
1021+ if readMonitor .Request .Assertions [0 ].Property != "avg" {
1022+ t .Fatalf ("wrong Assertion.Property after creation, got %s" , readMonitor .Request .Assertions [0 ].Property )
1023+ }
1024+
1025+ if readMonitor .Request .Assertions [0 ].Target != "500" {
1026+ t .Fatalf ("wrong Assertion.Target after creation" )
1027+ }
1028+
1029+ if len (readMonitor .Locations ) != 1 {
1030+ t .Fatalf ("wrong Locations count after creation" )
1031+ }
1032+
1033+ if readMonitor .Locations [0 ] != "us-east-1" {
1034+ t .Fatalf ("wrong Location after creation" )
1035+ }
1036+
1037+ updateMonitor := checkly.ICMPMonitor {
1038+ Name : "Bar ICMP monitor" ,
1039+ Frequency : 1 ,
1040+ Request : checkly.ICMPRequest {
1041+ Hostname : "api.checklyhq.com" ,
1042+ IPFamily : "IPv4" ,
1043+ PingCount : 3 ,
1044+ Assertions : []checkly.Assertion {
1045+ {
1046+ Source : "LATENCY" ,
1047+ Property : "max" ,
1048+ Target : "200" ,
1049+ Comparison : "LESS_THAN" ,
1050+ },
1051+ },
1052+ },
1053+ Locations : []string {"us-west-1" },
1054+ }
1055+
1056+ updatedMonitor , err := client .UpdateICMPMonitor (ctx , createdMonitor .ID , updateMonitor )
1057+ if err != nil {
1058+ t .Fatalf ("failed to update ICMP monitor: %v" , err )
1059+ }
1060+
1061+ if updatedMonitor .Name != "Bar ICMP monitor" {
1062+ t .Fatalf ("wrong Name after update" )
1063+ }
1064+
1065+ if updatedMonitor .Request .Hostname != "api.checklyhq.com" {
1066+ t .Fatalf ("wrong Hostname after update" )
1067+ }
1068+
1069+ if updatedMonitor .Request .PingCount != 3 {
1070+ t .Fatalf ("wrong PingCount after update, got %d" , updatedMonitor .Request .PingCount )
1071+ }
1072+
1073+ if len (updatedMonitor .Request .Assertions ) != 1 {
1074+ t .Fatalf ("wrong Assertion count after update" )
1075+ }
1076+
1077+ if updatedMonitor .Request .Assertions [0 ].Property != "max" {
1078+ t .Fatalf ("wrong Assertion.Property after update, got %s" , updatedMonitor .Request .Assertions [0 ].Property )
1079+ }
1080+
1081+ if updatedMonitor .Request .Assertions [0 ].Target != "200" {
1082+ t .Fatalf ("wrong Assertion.Target after update" )
1083+ }
1084+
1085+ if len (updatedMonitor .Locations ) != 1 {
1086+ t .Fatalf ("wrong Locations count after update" )
1087+ }
1088+
1089+ if updatedMonitor .Locations [0 ] != "us-west-1" {
1090+ t .Fatalf ("wrong Location after update" )
1091+ }
1092+
1093+ deleteOnce .Do (func () {
1094+ err := client .DeleteICMPMonitor (ctx , createdMonitor .ID )
1095+ if err != nil {
1096+ t .Fatalf ("failed to delete ICMP monitor: %v" , err )
1097+ }
1098+ })
1099+ }
1100+
1101+ func TestICMPMonitorGroupUnset (t * testing.T ) {
1102+ ctx := context .TODO ()
1103+
1104+ client := setupClient (t )
1105+
1106+ group , err := client .CreateGroup (ctx , checkly.Group {
1107+ Name : "Test Group" ,
1108+ Concurrency : 3 ,
1109+ Tags : []string {},
1110+ AlertSettings : checkly.AlertSettings {
1111+ EscalationType : checkly .RunBased ,
1112+ RunBasedEscalation : checkly.RunBasedEscalation {
1113+ FailedRunThreshold : 1 ,
1114+ },
1115+ },
1116+ Locations : []string {"us-east-1" },
1117+ })
1118+
1119+ if err != nil {
1120+ t .Fatalf ("failed to create group for ICMP monitor: %v" , err )
1121+ }
1122+
1123+ defer func () {
1124+ _ = client .DeleteGroup (ctx , group .ID )
1125+ }()
1126+
1127+ pendingMonitor := checkly.ICMPMonitor {
1128+ Name : "Foo ICMP monitor" ,
1129+ Frequency : 1 ,
1130+ Request : checkly.ICMPRequest {
1131+ Hostname : "welcome.checklyhq.com" ,
1132+ Assertions : []checkly.Assertion {},
1133+ },
1134+ Locations : []string {"us-east-1" },
1135+ GroupID : group .ID ,
1136+ }
1137+
1138+ createdMonitor , err := client .CreateICMPMonitor (ctx , pendingMonitor )
1139+ if err != nil {
1140+ t .Fatalf ("failed to create ICMP monitor: %v" , err )
1141+ }
1142+
1143+ defer func () {
1144+ _ = client .DeleteICMPMonitor (ctx , createdMonitor .ID )
1145+ }()
1146+
1147+ if createdMonitor .GroupID != group .ID {
1148+ t .Fatalf ("wrong GroupID after creation" )
1149+ }
1150+
1151+ updateMonitor := pendingMonitor
1152+ updateMonitor .GroupID = 0
1153+
1154+ updatedMonitor , err := client .UpdateICMPMonitor (ctx , createdMonitor .ID , updateMonitor )
1155+ if err != nil {
1156+ t .Fatalf ("failed to update ICMP monitor: %v" , err )
1157+ }
1158+
1159+ if updatedMonitor .GroupID != 0 {
1160+ t .Fatalf ("wrong GroupID after update" )
1161+ }
1162+ }
1163+
9601164func TestDNSMonitorGroupUnset (t * testing.T ) {
9611165 ctx := context .TODO ()
9621166
0 commit comments