@@ -1350,3 +1350,131 @@ 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 : "has notifyenforcer action - case insensitive" ,
1394+ spec : & v1alpha1.KProbeSpec {
1395+ Selectors : []v1alpha1.KProbeSelector {
1396+ {
1397+ MatchActions : []v1alpha1.ActionSelector {
1398+ {Action : "NotifyEnforcer" },
1399+ },
1400+ },
1401+ },
1402+ },
1403+ actionName : "notifyenforcer" ,
1404+ actionType : ActionTypeNotifyEnforcer ,
1405+ expectedResult : true ,
1406+ },
1407+ {
1408+ name : "does not have action" ,
1409+ spec : & v1alpha1.KProbeSpec {
1410+ Selectors : []v1alpha1.KProbeSelector {
1411+ {
1412+ MatchActions : []v1alpha1.ActionSelector {
1413+ {Action : "post" },
1414+ },
1415+ },
1416+ },
1417+ },
1418+ actionName : "sigkill" ,
1419+ actionType : ActionTypeSigKill ,
1420+ expectedResult : false ,
1421+ },
1422+ {
1423+ name : "multiple selectors with different actions" ,
1424+ spec : & v1alpha1.KProbeSpec {
1425+ Selectors : []v1alpha1.KProbeSelector {
1426+ {
1427+ MatchActions : []v1alpha1.ActionSelector {
1428+ {Action : "post" },
1429+ },
1430+ },
1431+ {
1432+ MatchActions : []v1alpha1.ActionSelector {
1433+ {Action : "sigkill" },
1434+ },
1435+ },
1436+ },
1437+ },
1438+ actionName : "sigkill" ,
1439+ actionType : ActionTypeSigKill ,
1440+ expectedResult : true ,
1441+ },
1442+ {
1443+ name : "multiple actions in one selector" ,
1444+ spec : & v1alpha1.KProbeSpec {
1445+ Selectors : []v1alpha1.KProbeSelector {
1446+ {
1447+ MatchActions : []v1alpha1.ActionSelector {
1448+ {Action : "post" },
1449+ {Action : "notifyenforcer" },
1450+ },
1451+ },
1452+ },
1453+ },
1454+ actionName : "notifyenforcer" ,
1455+ actionType : ActionTypeNotifyEnforcer ,
1456+ expectedResult : true ,
1457+ },
1458+ {
1459+ name : "empty spec" ,
1460+ spec : & v1alpha1.KProbeSpec {
1461+ Selectors : []v1alpha1.KProbeSelector {},
1462+ },
1463+ actionName : "sigkill" ,
1464+ actionType : ActionTypeSigKill ,
1465+ expectedResult : false ,
1466+ },
1467+ }
1468+
1469+ for _ , test := range tests {
1470+ t .Run (test .name , func (t * testing.T ) {
1471+ // Test string-based HasAction
1472+ result := HasAction (test .spec , test .actionName )
1473+ assert .Equal (t , test .expectedResult , result , "HasAction should match expected result" )
1474+
1475+ // Test type-based HasActionType
1476+ result = HasActionType (test .spec , test .actionType )
1477+ assert .Equal (t , test .expectedResult , result , "HasActionType should match expected result" )
1478+ })
1479+ }
1480+ }
0 commit comments