This is an automated email from the ASF dual-hosted git repository. DImuthuUpe pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 926755a0b87d1adf35dfd68fd35c9364a1da4aff Author: DImuthuUpe <[email protected]> AuthorDate: Sat May 23 15:30:11 2026 -0400 Validating subscriber tests through audit logs --- .../internal/subscribers/account.go | 94 +++++++-- .../subscribers/accountsub_integration_test.go | 212 ++++++++++++++++++++- dev-ops/local-slurm/Makefile | 8 +- internal/store/audit_event_store.go | 12 ++ internal/store/store.go | 2 + pkg/service/audit_event.go | 9 + pkg/service/interface.go | 1 + pkg/service/mock.go | 44 +++++ 8 files changed, 362 insertions(+), 20 deletions(-) diff --git a/connectors/SLURM/Association-Mapper/internal/subscribers/account.go b/connectors/SLURM/Association-Mapper/internal/subscribers/account.go index 095f5296a..8ab316e66 100644 --- a/connectors/SLURM/Association-Mapper/internal/subscribers/account.go +++ b/connectors/SLURM/Association-Mapper/internal/subscribers/account.go @@ -10,32 +10,32 @@ import ( "github.com/apache/airavata-custos/pkg/models" ) -func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAccount models.ComputeAllocation) { - slog.Info("Received compute allocation creation event", "account", computeAccount) +func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAllocation models.ComputeAllocation) { + slog.Info("Received compute allocation creation event", "account", computeAllocation) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - cluster, err := a.coreService.GetComputeCluster(ctx, computeAccount.ComputeClusterID) + cluster, err := a.coreService.GetComputeCluster(ctx, computeAllocation.ComputeClusterID) if err != nil { slog.Error("Failed to get compute cluster for allocation creation", "error", err) auditEvent := models.AuditEvent{ EventType: "ComputeAllocationCreationFailed", Details: err.Error(), - EntityID: computeAccount.ID, + EntityID: computeAllocation.ID, EventTime: time.Now(), } a.coreService.CreateAuditEvent(ctx, &auditEvent) return } - project, err := a.coreService.GetProject(ctx, computeAccount.ProjectID) + project, err := a.coreService.GetProject(ctx, computeAllocation.ProjectID) if err != nil { slog.Error("Failed to get project for allocation creation", "error", err) auditEvent := models.AuditEvent{ EventType: "ComputeAllocationCreationFailed", Details: err.Error(), - EntityID: computeAccount.ID, + EntityID: computeAllocation.ID, EventTime: time.Now(), } a.coreService.CreateAuditEvent(ctx, &auditEvent) @@ -48,7 +48,7 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAcco auditEvent := models.AuditEvent{ EventType: "ComputeAllocationCreationFailed", Details: err.Error(), - EntityID: computeAccount.ID, + EntityID: computeAllocation.ID, EventTime: time.Now(), } a.coreService.CreateAuditEvent(ctx, &auditEvent) @@ -61,7 +61,7 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAcco auditEvent := models.AuditEvent{ EventType: "ComputeAllocationCreationFailed", Details: err.Error(), - EntityID: computeAccount.ID, + EntityID: computeAllocation.ID, EventTime: time.Now(), } a.coreService.CreateAuditEvent(ctx, &auditEvent) @@ -69,8 +69,8 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAcco } slurmAccount := client.Account{ - Name: computeAccount.Name, - Description: computeAccount.Name, + Name: computeAllocation.Name, + Description: computeAllocation.Name, Organization: organization.Name, } @@ -80,7 +80,7 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAcco auditEvent := models.AuditEvent{ EventType: "ComputeAllocationCreationFailed", Details: err.Error(), - EntityID: computeAccount.ID, + EntityID: computeAllocation.ID, EventTime: time.Now(), } a.coreService.CreateAuditEvent(ctx, &auditEvent) @@ -90,7 +90,7 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAcco auditEvent := models.AuditEvent{ EventType: "ComputeAllocationCreationSucceeded", Details: "Successfully created SLURM account for compute allocation", - EntityID: computeAccount.ID, + EntityID: computeAllocation.ID, EventTime: time.Now(), } a.coreService.CreateAuditEvent(ctx, &auditEvent) @@ -98,12 +98,12 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationCreation(computeAcco slog.Info("Successfully created SLURM account for compute allocation", "account", slurmAccount) } -func (a *AssociationSubscriber) SubscribeToComputeAllocationDeletion(computeAccount models.ComputeAllocation) { - slog.Info("Received compute allocation deletion event", "account", computeAccount) +func (a *AssociationSubscriber) SubscribeToComputeAllocationDeletion(computeAllocation models.ComputeAllocation) { + slog.Info("Received compute allocation deletion event", "account", computeAllocation) } -func (a *AssociationSubscriber) SubscribeToComputeAllocationUpdate(computeAccount models.ComputeAllocation) { - slog.Info("Received compute allocation update event", "account", computeAccount) +func (a *AssociationSubscriber) SubscribeToComputeAllocationUpdate(computeAllocation models.ComputeAllocation) { + slog.Info("Received compute allocation update event", "account", computeAllocation) } func (a *AssociationSubscriber) SubscribeToComputeAllocationResourceMappingCreation(mapping models.ComputeAllocationResourceMapping) { @@ -115,24 +115,58 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationResourceMappingCreat allocation, err := a.coreService.GetComputeAllocation(ctx, mapping.ComputeAllocationID) if err != nil { slog.Error("Failed to get compute allocation for resource mapping creation", "error", err) + auditEvent := models.AuditEvent{ + EventType: "ComputeAllocationResourceMappingCreationFailed", + Details: err.Error(), + EntityID: mapping.ID, + EventTime: time.Now(), + } + a.coreService.CreateAuditEvent(ctx, &auditEvent) return } cluster, err := a.coreService.GetComputeCluster(ctx, allocation.ComputeClusterID) if err != nil { slog.Error("Failed to get compute cluster for resource mapping creation", "error", err) + auditEvent := models.AuditEvent{ + EventType: "ComputeAllocationResourceMappingCreationFailed", + Details: err.Error(), + EntityID: mapping.ID, + EventTime: time.Now(), + } + a.coreService.CreateAuditEvent(ctx, &auditEvent) return } resource, err := a.coreService.GetComputeAllocationResource(ctx, mapping.ComputeAllocationResourceID) if err != nil { slog.Error("Failed to get compute allocation resource for resource mapping creation", "error", err) + auditEvent := models.AuditEvent{ + EventType: "ComputeAllocationResourceMappingCreationFailed", + Details: err.Error(), + EntityID: mapping.ID, + EventTime: time.Now(), + } + a.coreService.CreateAuditEvent(ctx, &auditEvent) return } grpTres := []client.TRES{} if mapping.ResourceAmount > 0 { + + if resource.ResourceType == "" { + slog.Error("Resource type is empty for resource mapping creation", "mapping", mapping) + auditEvent := models.AuditEvent{ + EventType: "ComputeAllocationResourceMappingCreationFailed", + Details: "Resource type is empty for resource mapping creation", + EntityID: mapping.ID, + EventTime: time.Now(), + } + a.coreService.CreateAuditEvent(ctx, &auditEvent) + return + } + grpTres = append(grpTres, client.TRES{ Type: resource.ResourceType, Count: mapping.ResourceAmount, @@ -141,6 +175,19 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationResourceMappingCreat grpTresMins := []client.TRES{} if mapping.ResourceTime > 0 { + + if resource.ResourceType == "" { + slog.Error("Resource type is empty for resource mapping creation", "mapping", mapping) + auditEvent := models.AuditEvent{ + EventType: "ComputeAllocationResourceMappingCreationFailed", + Details: "Resource type is empty for resource mapping creation", + EntityID: mapping.ID, + EventTime: time.Now(), + } + a.coreService.CreateAuditEvent(ctx, &auditEvent) + return + } + grpTresMins = append(grpTresMins, client.TRES{ Type: resource.ResourceType, Count: mapping.ResourceTime, @@ -161,7 +208,22 @@ func (a *AssociationSubscriber) SubscribeToComputeAllocationResourceMappingCreat err = a.slurmClient.UpsertAssociation(association) if err != nil { slog.Error("Failed to upsert association for membership resource override creation", "error", err) + auditEvent := models.AuditEvent{ + EventType: "ComputeAllocationResourceMappingCreationFailed", + Details: err.Error(), + EntityID: mapping.ID, + EventTime: time.Now(), + } + a.coreService.CreateAuditEvent(ctx, &auditEvent) + return } else { slog.Info("Successfully upserted association for membership resource override creation", "association", association) + auditEvent := models.AuditEvent{ + EventType: "ComputeAllocationResourceMappingCreationSucceeded", + Details: "Successfully upserted association for compute allocation resource mapping creation", + EntityID: mapping.ID, + EventTime: time.Now(), + } + a.coreService.CreateAuditEvent(ctx, &auditEvent) } } diff --git a/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go b/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go index 59881c481..2490e1297 100644 --- a/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go +++ b/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go @@ -1,13 +1,14 @@ package subscribers import ( - "os" - "testing" - + //"log" "context" + "fmt" operations "github.com/apache/airavata-custos/connectors/SLURM/Association-Mapper/internal/operations" "github.com/apache/airavata-custos/pkg/models" "github.com/apache/airavata-custos/pkg/service" + "os" + "testing" ) func TestSubscribeToComputeAllocationCreation(t *testing.T) { @@ -133,5 +134,210 @@ func TestSubscribeToComputeAllocationCreationWrongCluster(t *testing.T) { } client.DeleteAccount(computeAccount.Name) // clean up after test +} + +func createAllocationMapping(client *operations.Client, mockCoreService *service.CoreServiceMock, clusterID string, clusterName string, + computeAllocationID string, computeAllocationName string, + projectID string, allocationMappingId string, + allocationResourceId string, partitionName string) error { + + associationSubscriber := NewAssociationSubscriber(client, nil, mockCoreService) + + computeAllocation := models.ComputeAllocation{ + ID: computeAllocationID, + Name: computeAllocationName, + ProjectID: projectID, + ComputeClusterID: clusterID, + } + + associationSubscriber.SubscribeToComputeAllocationCreation(computeAllocation) + + allAuditEvents, err := mockCoreService.ListAllAuditEvents(context.Background()) + + if err != nil { + return fmt.Errorf("Failed to list all audit events: %v", err) + } + + if len(allAuditEvents) == 0 { + return fmt.Errorf("Expected at least one audit event after resource mapping creation, but got none") + } + + if len(allAuditEvents) > 0 { + lastEvent := allAuditEvents[len(allAuditEvents)-1] + if lastEvent.EventType != "ComputeAllocationCreationSucceeded" { + return fmt.Errorf("Expected audit event type 'ComputeAllocationCreationSucceeded', got '%s'", lastEvent.EventType) + } + if lastEvent.EntityID != computeAllocation.ID { + return fmt.Errorf("Expected audit event EntityID '%s', got '%s'", computeAllocation.ID, lastEvent.EntityID) + } + } + + resourceMapping := models.ComputeAllocationResourceMapping{ + ID: allocationMappingId, + ComputeAllocationID: computeAllocation.ID, + ComputeAllocationResourceID: allocationResourceId, + ResourceAmount: 10, + ResourceTime: 100, + } + + associationSubscriber.SubscribeToComputeAllocationResourceMappingCreation(resourceMapping) + + allAuditEvents, err = mockCoreService.ListAllAuditEvents(context.Background()) + + if err != nil { + return fmt.Errorf("Failed to list all audit events: %v", err) + } + if len(allAuditEvents) == 0 { + return fmt.Errorf("Expected at least one audit event after resource mapping creation, but got none") + } + if len(allAuditEvents) > 0 { + lastEvent := allAuditEvents[len(allAuditEvents)-1] + if lastEvent.EventType != "ComputeAllocationResourceMappingCreationSucceeded" { + return fmt.Errorf("Expected audit event type 'ComputeAllocationResourceMappingCreationSucceeded', got '%s'", lastEvent.EventType) + } + if lastEvent.EntityID != resourceMapping.ID { + return fmt.Errorf("Expected audit event EntityID '%s', got '%s'", resourceMapping.ID, lastEvent.EntityID) + } + } + + return nil +} + +func TestSubscribeToComputeAllocationResourceMappingCreation(t *testing.T) { + if !operations.IsLocalSlurmConfigAvailable() { + t.Skip("Skipping integration test for compute allocation creation subscription because local SLURM config is not available") + } + + apiUrl := os.Getenv("TEST_SLURM_API") + user := os.Getenv("TEST_SLURM_USER") + token := os.Getenv("TEST_SLURM_TOKEN") + apiVersion := os.Getenv("TEST_SLURM_API_VERSION") + + client := operations.New(apiUrl, user, token, apiVersion) + + clusterID := "cluster-001" + clusterName := "artisan" + projectID := "project-001" + computeAllocationID := "compute-allocation-001" + computeAllocationName := "MD Allocation" + partitionName := "compute" + allocationResourceId := "allocation-resource-001" + allocationMappingId := "allocation-mapping-001" + + defer client.DeleteAccount(computeAllocationName) // clean up after test + defer client.DeleteAssociation(operations.AssocFilter{Account: computeAllocationName}) // clean up after test + + auditEvents := make([]*models.AuditEvent, 0) + + mockCoreService := &service.CoreServiceMock{ + GetComputeClusterFunc: func(ctx context.Context, clusterID string) (*models.ComputeCluster, error) { + return &models.ComputeCluster{ID: clusterID, Name: clusterName}, nil + }, + GetProjectFunc: func(ctx context.Context, id string) (*models.Project, error) { + return &models.Project{ID: id, Title: "PROJ001", Status: "ACTIVE"}, nil + }, + GetUserFunc: func(ctx context.Context, id string) (*models.User, error) { + return &models.User{ID: id, OrganizationID: "GATECH"}, nil + }, + GetOrganizationFunc: func(ctx context.Context, id string) (*models.Organization, error) { + return &models.Organization{ID: id, Name: "Georgia Institute of Technology"}, nil + }, + CreateAuditEventFunc: func(ctx context.Context, event *models.AuditEvent) (*models.AuditEvent, error) { + auditEvents = append(auditEvents, event) + return event, nil + }, + GetComputeAllocationFunc: func(ctx context.Context, id string) (*models.ComputeAllocation, error) { + return &models.ComputeAllocation{ID: id, Name: computeAllocationName, ComputeClusterID: clusterID}, nil + }, + GetComputeAllocationResourceFunc: func(ctx context.Context, id string) (*models.ComputeAllocationResource, error) { + return &models.ComputeAllocationResource{ID: id, Name: partitionName, ResourceType: "cpu8", ResourceAmount: 1000}, nil + }, + ListAllAuditEventsFunc: func(ctx context.Context) ([]*models.AuditEvent, error) { + return auditEvents, nil + }, + } + + err := createAllocationMapping(client, mockCoreService, clusterID, clusterName, + computeAllocationID, computeAllocationName, + projectID, allocationMappingId, allocationResourceId, + partitionName) + if err != nil { + t.Fatalf("Failed to create allocation mapping: %v", err) + } + +} + +func TestSubscribeToComputeAllocationResourceMappingWrongClusterCreation(t *testing.T) { + + // Pass the wrong cluster name in the mock to simulate the case where the cluster + // associated with the compute allocation does not match any cluster in SLURM, + // which should result in a failure to create the association and an audit event + // being created for the failure + + if !operations.IsLocalSlurmConfigAvailable() { + t.Skip("Skipping integration test for compute allocation creation subscription because local SLURM config is not available") + } + + apiUrl := os.Getenv("TEST_SLURM_API") + user := os.Getenv("TEST_SLURM_USER") + token := os.Getenv("TEST_SLURM_TOKEN") + apiVersion := os.Getenv("TEST_SLURM_API_VERSION") + + client := operations.New(apiUrl, user, token, apiVersion) + + clusterID := "cluster-001" + clusterName := "wrong_cluster_name" // this is intentionally wrong to simulate the error case + projectID := "project-001" + computeAllocationID := "compute-allocation-001" + computeAllocationName := "MD Allocation" + partitionName := "compute" + allocationResourceId := "allocation-resource-001" + allocationMappingId := "allocation-mapping-001" + + defer client.DeleteAccount(computeAllocationName) // clean up after test + defer client.DeleteAssociation(operations.AssocFilter{Account: computeAllocationName}) // clean up after test + + auditEvents := make([]*models.AuditEvent, 0) + + mockCoreService := &service.CoreServiceMock{ + GetComputeClusterFunc: func(ctx context.Context, clusterID string) (*models.ComputeCluster, error) { + return &models.ComputeCluster{ID: clusterID, Name: clusterName}, nil + }, + GetProjectFunc: func(ctx context.Context, id string) (*models.Project, error) { + return &models.Project{ID: id, Title: "PROJ001", Status: "ACTIVE"}, nil + }, + GetUserFunc: func(ctx context.Context, id string) (*models.User, error) { + return &models.User{ID: id, OrganizationID: "GATECH"}, nil + }, + GetOrganizationFunc: func(ctx context.Context, id string) (*models.Organization, error) { + return &models.Organization{ID: id, Name: "Georgia Institute of Technology"}, nil + }, + CreateAuditEventFunc: func(ctx context.Context, event *models.AuditEvent) (*models.AuditEvent, error) { + auditEvents = append(auditEvents, event) + return event, nil + }, + GetComputeAllocationFunc: func(ctx context.Context, id string) (*models.ComputeAllocation, error) { + return &models.ComputeAllocation{ID: id, Name: computeAllocationName, ComputeClusterID: clusterID}, nil + }, + GetComputeAllocationResourceFunc: func(ctx context.Context, id string) (*models.ComputeAllocationResource, error) { + return &models.ComputeAllocationResource{ID: id, Name: partitionName, ResourceType: "cpu", ResourceAmount: 1000}, nil + }, + ListAllAuditEventsFunc: func(ctx context.Context) ([]*models.AuditEvent, error) { + return auditEvents, nil + }, + } + + err := createAllocationMapping(client, mockCoreService, clusterID, clusterName, + computeAllocationID, computeAllocationName, + projectID, allocationMappingId, allocationResourceId, + partitionName) + if err != nil { + expectedErrorMsg := "Expected audit event type 'ComputeAllocationCreationSucceeded', got 'ComputeAllocationCreationFailed'" + if err.Error() != expectedErrorMsg { + t.Fatalf("Expected error message '%s', got '%s'", expectedErrorMsg, err.Error()) + } + } else { + t.Fatal("Expected error due to wrong cluster name, but got nil") + } } diff --git a/dev-ops/local-slurm/Makefile b/dev-ops/local-slurm/Makefile index e7ac5f228..4a97eb535 100644 --- a/dev-ops/local-slurm/Makefile +++ b/dev-ops/local-slurm/Makefile @@ -30,4 +30,10 @@ logs: docker compose logs -f --tail=100 token: - docker compose exec login scontrol token \ No newline at end of file + docker compose exec login scontrol token + +allocations: + docker compose exec login sacct -n -o JobID,State --starttime now-5minutes + +associations: + docker compose exec login sacctmgr list associations format=Account,User,GrpTRES,GrpTRESMins,QOS \ No newline at end of file diff --git a/internal/store/audit_event_store.go b/internal/store/audit_event_store.go index 9ac34e590..db275c793 100644 --- a/internal/store/audit_event_store.go +++ b/internal/store/audit_event_store.go @@ -77,6 +77,18 @@ func (s *mysqlAuditEventStore) FindByEventType(ctx context.Context, eventType st return rows, nil } +func (s *mysqlAuditEventStore) ListAll(ctx context.Context) ([]*models.AuditEvent, error) { + var rows []*models.AuditEvent + err := s.db.SelectContext(ctx, &rows, + `SELECT `+auditEventColumns+` + FROM audit_events + ORDER BY event_time`) + if err != nil { + return nil, err + } + return rows, nil +} + func (s *mysqlAuditEventStore) Create(ctx context.Context, tx *sql.Tx, e *models.AuditEvent) error { _, err := tx.ExecContext(ctx, `INSERT INTO audit_events (id, event_type, event_time, entity_id, details) diff --git a/internal/store/store.go b/internal/store/store.go index 38bb9129c..1cae3728f 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -320,6 +320,8 @@ type AuditEventStore interface { // FindByEventType returns every audit event of the given type, ordered by // event_time ascending. FindByEventType(ctx context.Context, eventType string) ([]models.AuditEvent, error) + // ListAll returns every audit event ordered by event_time ascending. + ListAll(ctx context.Context) ([]*models.AuditEvent, error) // Create inserts a new audit event within the provided transaction. Create(ctx context.Context, tx *sql.Tx, e *models.AuditEvent) error // Delete removes an audit event by ID within the provided transaction. diff --git a/pkg/service/audit_event.go b/pkg/service/audit_event.go index d0ace4f87..259751498 100644 --- a/pkg/service/audit_event.go +++ b/pkg/service/audit_event.go @@ -93,6 +93,15 @@ func (s *Service) ListAuditEventsByEventType(ctx context.Context, eventType stri return rows, nil } +// ListAllAuditEvents returns every audit event ordered by event_time ascending. +func (s *Service) ListAllAuditEvents(ctx context.Context) ([]*models.AuditEvent, error) { + rows, err := s.auditEvents.ListAll(ctx) + if err != nil { + return nil, fmt.Errorf("list all audit events: %w", err) + } + return rows, nil +} + // DeleteAuditEvent removes an audit event by ID. func (s *Service) DeleteAuditEvent(ctx context.Context, id string) error { if id == "" { diff --git a/pkg/service/interface.go b/pkg/service/interface.go index 3e493c55d..bfbb65337 100644 --- a/pkg/service/interface.go +++ b/pkg/service/interface.go @@ -210,6 +210,7 @@ type AuditEventService interface { GetAuditEvent(ctx context.Context, id string) (*models.AuditEvent, error) ListAuditEventsByEntity(ctx context.Context, entityID string) ([]models.AuditEvent, error) ListAuditEventsByEventType(ctx context.Context, eventType string) ([]models.AuditEvent, error) + ListAllAuditEvents(ctx context.Context) ([]*models.AuditEvent, error) DeleteAuditEvent(ctx context.Context, id string) error } diff --git a/pkg/service/mock.go b/pkg/service/mock.go index e927657c3..b60278d1e 100644 --- a/pkg/service/mock.go +++ b/pkg/service/mock.go @@ -212,6 +212,9 @@ var _ CoreService = &CoreServiceMock{} // GetUserIdentityBySourceAndExternalIDFunc: func(ctx context.Context, source string, externalID string) (*models.UserIdentity, error) { // panic("mock out the GetUserIdentityBySourceAndExternalID method") // }, +// ListAllAuditEventsFunc: func(ctx context.Context) ([]*models.AuditEvent, error) { +// panic("mock out the ListAllAuditEvents method") +// }, // ListAllocationsForResourceFunc: func(ctx context.Context, resourceID string) ([]models.ComputeAllocation, error) { // panic("mock out the ListAllocationsForResource method") // }, @@ -534,6 +537,9 @@ type CoreServiceMock struct { // GetUserIdentityBySourceAndExternalIDFunc mocks the GetUserIdentityBySourceAndExternalID method. GetUserIdentityBySourceAndExternalIDFunc func(ctx context.Context, source string, externalID string) (*models.UserIdentity, error) + // ListAllAuditEventsFunc mocks the ListAllAuditEvents method. + ListAllAuditEventsFunc func(ctx context.Context) ([]*models.AuditEvent, error) + // ListAllocationsForResourceFunc mocks the ListAllocationsForResource method. ListAllocationsForResourceFunc func(ctx context.Context, resourceID string) ([]models.ComputeAllocation, error) @@ -1127,6 +1133,11 @@ type CoreServiceMock struct { // ExternalID is the externalID argument value. ExternalID string } + // ListAllAuditEvents holds details about calls to the ListAllAuditEvents method. + ListAllAuditEvents []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } // ListAllocationsForResource holds details about calls to the ListAllocationsForResource method. ListAllocationsForResource []struct { // Ctx is the ctx argument value. @@ -1489,6 +1500,7 @@ type CoreServiceMock struct { lockGetUserIdentity sync.RWMutex lockGetUserIdentityByOIDCSub sync.RWMutex lockGetUserIdentityBySourceAndExternalID sync.RWMutex + lockListAllAuditEvents sync.RWMutex lockListAllocationsForResource sync.RWMutex lockListAllocationsForUser sync.RWMutex lockListAuditEventsByEntity sync.RWMutex @@ -3876,6 +3888,38 @@ func (mock *CoreServiceMock) GetUserIdentityBySourceAndExternalIDCalls() []struc return calls } +// ListAllAuditEvents calls ListAllAuditEventsFunc. +func (mock *CoreServiceMock) ListAllAuditEvents(ctx context.Context) ([]*models.AuditEvent, error) { + if mock.ListAllAuditEventsFunc == nil { + panic("CoreServiceMock.ListAllAuditEventsFunc: method is nil but CoreService.ListAllAuditEvents was just called") + } + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockListAllAuditEvents.Lock() + mock.calls.ListAllAuditEvents = append(mock.calls.ListAllAuditEvents, callInfo) + mock.lockListAllAuditEvents.Unlock() + return mock.ListAllAuditEventsFunc(ctx) +} + +// ListAllAuditEventsCalls gets all the calls that were made to ListAllAuditEvents. +// Check the length with: +// +// len(mockedCoreService.ListAllAuditEventsCalls()) +func (mock *CoreServiceMock) ListAllAuditEventsCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockListAllAuditEvents.RLock() + calls = mock.calls.ListAllAuditEvents + mock.lockListAllAuditEvents.RUnlock() + return calls +} + // ListAllocationsForResource calls ListAllocationsForResourceFunc. func (mock *CoreServiceMock) ListAllocationsForResource(ctx context.Context, resourceID string) ([]models.ComputeAllocation, error) { if mock.ListAllocationsForResourceFunc == nil {
