validators

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package testutil provides test utilities for Kubernaut services.

Package validators provides CRD status validation helpers for E2E and unit tests. See docs/testing/test-plans/FULLPIPELINE_E2E_STATUS_VALIDATION_TEST_PLAN.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventOutcomePtr

EventOutcomePtr returns a pointer to the given EventOutcome. Usage: EventOutcome: testutil.EventOutcomePtr(ogenclient.AuditEventEventOutcomeSuccess)

func IntPtr

func IntPtr(i int) *int

IntPtr returns a pointer to the given int.

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to the given string.

func ValidateAAStatus

func ValidateAAStatus(aa *aianalysisv1.AIAnalysis, opts ...ValidationOption) []string

ValidateAAStatus validates AIAnalysis status fields (23 base + 9 approval = 32 with approval).

func ValidateAuditEvent

func ValidateAuditEvent(event ogenclient.AuditEvent, expected ExpectedAuditEvent)

ValidateAuditEvent validates that an audit event matches expected values. Use this helper to ensure consistent audit field validation across all tests.

Example usage:

severity := "info"
testutil.ValidateAuditEvent(event, testutil.ExpectedAuditEvent{
    EventType:     "signal.categorization.completed",
    EventCategory: ogenclient.AuditEventEventCategorySignalprocessing,
    EventAction:   "categorize",
    EventOutcome:  ogenclient.AuditEventEventOutcomeSuccess,
    CorrelationID: string(sp.UID),
    Severity:      &severity,
    EventDataFields: map[string]interface{}{
        "signal_name": "TestSignal",
    },
})

func ValidateAuditEventHasRequiredFields

func ValidateAuditEventHasRequiredFields(event ogenclient.AuditEvent)

ValidateAuditEventHasRequiredFields validates that all standard audit fields are present. Use this for quick validation that event structure is correct.

func ValidateEAStatus

func ValidateEAStatus(ea *eav1.EffectivenessAssessment) []string

ValidateEAStatus validates EffectivenessAssessment status fields (8 checks).

func ValidateNTStatus

func ValidateNTStatus(nr *notificationv1.NotificationRequest) []string

ValidateNTStatus validates NotificationRequest status fields (8 checks).

func ValidateRARSpec

func ValidateRARSpec(rar *remediationv1.RemediationApprovalRequest) []string

ValidateRARSpec validates RemediationApprovalRequest spec fields (13 checks).

func ValidateRARStatus

func ValidateRARStatus(rar *remediationv1.RemediationApprovalRequest) []string

ValidateRARStatus validates RemediationApprovalRequest status fields (6 checks).

func ValidateRRStatus

func ValidateRRStatus(rr *remediationv1.RemediationRequest, opts ...ValidationOption) []string

ValidateRRStatus validates RemediationRequest status fields (15 base + 2 approval = 17 with approval).

func ValidateSPStatus

func ValidateSPStatus(sp *signalprocessingv1.SignalProcessing) []string

ValidateSPStatus validates SignalProcessing status fields (23 checks).

func ValidateWEStatus

func ValidateWEStatus(we *workflowexecutionv1.WorkflowExecution) []string

ValidateWEStatus validates WorkflowExecution status fields (9 checks).

Types

type AuditEventMatcher

type AuditEventMatcher struct {
	// contains filtered or unexported fields
}

AuditEventMatcher is a Gomega matcher for audit events. Example: Expect(event).To(MatchAuditEvent(expected))

func MatchAuditEvent

func MatchAuditEvent(expected ExpectedAuditEvent) *AuditEventMatcher

MatchAuditEvent returns a Gomega matcher for audit events.

func (*AuditEventMatcher) FailureMessage

func (m *AuditEventMatcher) FailureMessage(actual interface{}) string

FailureMessage implements GomegaMatcher.

func (*AuditEventMatcher) Match

func (m *AuditEventMatcher) Match(actual interface{}) (bool, error)

Match implements GomegaMatcher.

func (*AuditEventMatcher) NegatedFailureMessage

func (m *AuditEventMatcher) NegatedFailureMessage(actual interface{}) string

NegatedFailureMessage implements GomegaMatcher.

type ExpectedAuditEvent

type ExpectedAuditEvent struct {
	// Required fields (always validated)
	EventType     string
	EventCategory ogenclient.AuditEventEventCategory // Use response type, not request type
	EventAction   string

	// Optional fields (validated only if non-empty/non-nil)
	EventOutcome  *ogenclient.AuditEventEventOutcome // Optional: may vary (e.g., HolmesGPT errors)
	CorrelationID string
	Severity      *string // Pointer type per schema
	ActorID       *string
	ActorType     *string
	ResourceID    *string
	ResourceType  *string
	Namespace     *string
	ClusterName   *string

	// EventData fields (validated if non-nil)
	EventDataFields map[string]interface{}
}

ExpectedAuditEvent defines expected values for an audit event. Fields left empty (zero value) will not be validated. Based on ogenclient.AuditEvent schema from pkg/datastorage/client/generated.go

type ValidationOption

type ValidationOption func(*validationConfig)

ValidationOption configures validator behavior.

func WithApprovalFlow

func WithApprovalFlow() ValidationOption

WithApprovalFlow enables approval-flow-specific validation (extra fields for AA and RR).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL