@@ -1350,3 +1350,71 @@ func TestParseCapabilityMask(t *testing.T) {
13501350 _ , err = parseCapabilitiesMask ("CAP_PIZZA" )
13511351 assert .Error (t , err )
13521352}
1353+
1354+ func TestHasAction (t * testing.T ) {
1355+ tests := []struct {
1356+ name string
1357+ spec * v1alpha1.KProbeSpec
1358+ actionName string
1359+ actionType int32
1360+ expectedResult bool
1361+ }{
1362+ {
1363+ name : "has sigkill action - string match" ,
1364+ spec : & v1alpha1.KProbeSpec {
1365+ Selectors : []v1alpha1.KProbeSelector {
1366+ {
1367+ MatchActions : []v1alpha1.ActionSelector {
1368+ {Action : "sigkill" },
1369+ },
1370+ },
1371+ },
1372+ },
1373+ actionName : "sigkill" ,
1374+ actionType : ActionTypeSigKill ,
1375+ expectedResult : true ,
1376+ },
1377+ {
1378+ name : "has sigkill action - case insensitive" ,
1379+ spec : & v1alpha1.KProbeSpec {
1380+ Selectors : []v1alpha1.KProbeSelector {
1381+ {
1382+ MatchActions : []v1alpha1.ActionSelector {
1383+ {Action : "SIGKILL" },
1384+ },
1385+ },
1386+ },
1387+ },
1388+ actionName : "sigkill" ,
1389+ actionType : ActionTypeSigKill ,
1390+ expectedResult : true ,
1391+ },
1392+ {
1393+ name : "does not have action" ,
1394+ spec : & v1alpha1.KProbeSpec {
1395+ Selectors : []v1alpha1.KProbeSelector {
1396+ {
1397+ MatchActions : []v1alpha1.ActionSelector {
1398+ {Action : "post" },
1399+ },
1400+ },
1401+ },
1402+ },
1403+ actionName : "sigkill" ,
1404+ actionType : ActionTypeSigKill ,
1405+ expectedResult : false ,
1406+ },
1407+ }
1408+
1409+ for _ , test := range tests {
1410+ t .Run (test .name , func (t * testing.T ) {
1411+ // Test string-based HasAction
1412+ result := HasAction (test .spec , test .actionName )
1413+ assert .Equal (t , test .expectedResult , result , "HasAction should match expected result" )
1414+
1415+ // Test type-based HasActionType
1416+ result = HasActionType (test .spec , test .actionType )
1417+ assert .Equal (t , test .expectedResult , result , "HasActionType should match expected result" )
1418+ })
1419+ }
1420+ }
0 commit comments