This is an automated email from the ASF dual-hosted git repository.

DImuthuUpe pushed a commit to branch service-mock
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git


The following commit(s) were added to refs/heads/service-mock by this push:
     new 5dd527b13 Adding integration tests for 
SubscribeToComputeAllocationMembershipCreation
5dd527b13 is described below

commit 5dd527b13275e62262b55c80f920db79a50fdf22
Author: DImuthuUpe <[email protected]>
AuthorDate: Sun May 24 08:59:45 2026 -0400

    Adding integration tests for SubscribeToComputeAllocationMembershipCreation
---
 .../internal/subscribers/account.go                | 105 +++---------------
 .../subscribers/accountsub_integration_test.go     |  76 +++++++++++++
 .../internal/subscribers/members.go                |  17 ++-
 .../subscribers/members_integration_test.go        | 117 +++++++++++++++++++++
 .../internal/subscribers/subscriber.go             |  22 +++-
 5 files changed, 241 insertions(+), 96 deletions(-)

diff --git 
a/connectors/SLURM/Association-Mapper/internal/subscribers/account.go 
b/connectors/SLURM/Association-Mapper/internal/subscribers/account.go
index 8ab316e66..fb7f69f57 100644
--- a/connectors/SLURM/Association-Mapper/internal/subscribers/account.go
+++ b/connectors/SLURM/Association-Mapper/internal/subscribers/account.go
@@ -19,52 +19,28 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationCreation(computeAllo
        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:  computeAllocation.ID,
-                       EventTime: time.Now(),
-               }
-               a.coreService.CreateAuditEvent(ctx, &auditEvent)
+               a.recordAuditEvent("ComputeAllocationCreationFailed", 
computeAllocation.ID, "Failed to get compute cluster. Error: "+err.Error())
                return
        }
 
        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:  computeAllocation.ID,
-                       EventTime: time.Now(),
-               }
-               a.coreService.CreateAuditEvent(ctx, &auditEvent)
+               a.recordAuditEvent("ComputeAllocationCreationFailed", 
computeAllocation.ID, "Failed to get project. Error: "+err.Error())
                return
        }
 
        pi, err := a.coreService.GetUser(ctx, project.ProjectPIID)
        if err != nil {
                slog.Error("Failed to get project PI for allocation creation", 
"error", err)
-               auditEvent := models.AuditEvent{
-                       EventType: "ComputeAllocationCreationFailed",
-                       Details:   err.Error(),
-                       EntityID:  computeAllocation.ID,
-                       EventTime: time.Now(),
-               }
-               a.coreService.CreateAuditEvent(ctx, &auditEvent)
+               a.recordAuditEvent("ComputeAllocationCreationFailed", 
computeAllocation.ID, "Failed to get project PI. Error: "+err.Error())
                return
        }
 
        organization, err := a.coreService.GetOrganization(ctx, 
pi.OrganizationID)
        if err != nil {
                slog.Error("Failed to get organization for allocation 
creation", "error", err)
-               auditEvent := models.AuditEvent{
-                       EventType: "ComputeAllocationCreationFailed",
-                       Details:   err.Error(),
-                       EntityID:  computeAllocation.ID,
-                       EventTime: time.Now(),
-               }
-               a.coreService.CreateAuditEvent(ctx, &auditEvent)
+               a.recordAuditEvent("ComputeAllocationCreationFailed", 
computeAllocation.ID, "Failed to get organization. Error: "+err.Error())
                return
        }
 
@@ -77,24 +53,11 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationCreation(computeAllo
        err = a.slurmClient.CreateAccount(slurmAccount, cluster.Name) // TODO: 
where to get cluster name from?
        if err != nil {
                slog.Error("Failed to create SLURM account", "error", err)
-               auditEvent := models.AuditEvent{
-                       EventType: "ComputeAllocationCreationFailed",
-                       Details:   err.Error(),
-                       EntityID:  computeAllocation.ID,
-                       EventTime: time.Now(),
-               }
-               a.coreService.CreateAuditEvent(ctx, &auditEvent)
+               a.recordAuditEvent("ComputeAllocationCreationFailed", 
computeAllocation.ID, "Failed to create SLURM account. Error: "+err.Error())
                return
        }
 
-       auditEvent := models.AuditEvent{
-               EventType: "ComputeAllocationCreationSucceeded",
-               Details:   "Successfully created SLURM account for compute 
allocation",
-               EntityID:  computeAllocation.ID,
-               EventTime: time.Now(),
-       }
-       a.coreService.CreateAuditEvent(ctx, &auditEvent)
-
+       a.recordAuditEvent("ComputeAllocationCreationSucceeded", 
computeAllocation.ID, "Successfully created SLURM account for compute 
allocation.")
        slog.Info("Successfully created SLURM account for compute allocation", 
"account", slurmAccount)
 }
 
@@ -115,39 +78,21 @@ 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)
+               
a.recordAuditEvent("ComputeAllocationResourceMappingCreationFailed", 
mapping.ID, "Failed to get compute allocation. Error: "+err.Error())
                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)
+               
a.recordAuditEvent("ComputeAllocationResourceMappingCreationFailed", 
mapping.ID, "Failed to get compute cluster. Error: "+err.Error())
                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)
+               
a.recordAuditEvent("ComputeAllocationResourceMappingCreationFailed", 
mapping.ID, "Failed to get compute allocation resource. Error: "+err.Error())
                return
        }
 
@@ -157,13 +102,7 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationResourceMappingCreat
 
                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)
+                       
a.recordAuditEvent("ComputeAllocationResourceMappingCreationFailed", 
mapping.ID, "Resource type is empty for resource mapping creation")
                        return
                }
 
@@ -178,13 +117,7 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationResourceMappingCreat
 
                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)
+                       
a.recordAuditEvent("ComputeAllocationResourceMappingCreationFailed", 
mapping.ID, "Resource type is empty for resource mapping creation")
                        return
                }
 
@@ -208,22 +141,10 @@ 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)
+               
a.recordAuditEvent("ComputeAllocationResourceMappingCreationFailed", 
mapping.ID, "Failed to upsert association. Error: "+err.Error())
                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)
+               
a.recordAuditEvent("ComputeAllocationResourceMappingCreationSucceeded", 
mapping.ID, "Successfully upserted association for compute allocation resource 
mapping creation")
        }
 }
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 5e5758d07..613d778bc 100644
--- 
a/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go
+++ 
b/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go
@@ -340,3 +340,79 @@ func 
TestSubscribeToComputeAllocationResourceMappingWrongClusterCreation(t *test
                t.Fatal("Expected error due to wrong cluster name, but got nil")
        }
 }
+
+func 
TestSubscribeToComputeAllocationResourceMappingWrongResourceTypeCreation(t 
*testing.T) {
+
+       // Passing the wrong resource type in the mock to simulate the case 
where the
+       // resource type of the allocation resource is not compatible with 
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 := "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 a resource type that is not compatible with 
SLURM to simulate the error case where the
+                       //resource mapping creation fails due to invalid 
resource type. Test cluster does not have gpu
+                       return &models.ComputeAllocationResource{ID: id, Name: 
partitionName, ResourceType: "gpu", 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 
'ComputeAllocationResourceMappingCreationSucceeded', got 
'ComputeAllocationResourceMappingCreationFailed'"
+               if err.Error() != expectedErrorMsg {
+                       t.Fatalf("Expected error message '%s', got '%s'", 
expectedErrorMsg, err.Error())
+               }
+       } else {
+               t.Fatal("Expected error due to wrong resource type, but got 
nil")
+       }
+}
diff --git 
a/connectors/SLURM/Association-Mapper/internal/subscribers/members.go 
b/connectors/SLURM/Association-Mapper/internal/subscribers/members.go
index 2a087ab60..c36cfc453 100644
--- a/connectors/SLURM/Association-Mapper/internal/subscribers/members.go
+++ b/connectors/SLURM/Association-Mapper/internal/subscribers/members.go
@@ -21,30 +21,35 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationMembershipCreation(
        allocation, err := a.coreService.GetComputeAllocation(ctx, 
membership.ComputeAllocationID)
        if err != nil {
                slog.Error("Failed to get compute allocation", "error", err)
+               a.recordAuditEvent("ComputeAllocationMembershipCreationFailed", 
membership.ID, "Failed to get compute allocation. Error: "+err.Error())
                return
        }
 
        cluster, err := a.coreService.GetComputeCluster(ctx, 
allocation.ComputeClusterID)
        if err != nil {
                slog.Error("Failed to get compute cluster", "error", err)
+               a.recordAuditEvent("ComputeAllocationMembershipCreationFailed", 
membership.ID, "Failed to get compute cluster. Error: "+err.Error())
                return
        }
 
        user, err := a.coreService.GetUser(ctx, membership.UserID)
        if err != nil {
                slog.Error("Failed to get user", "error", err)
+               a.recordAuditEvent("ComputeAllocationMembershipCreationFailed", 
membership.ID, "Failed to get user. Error: "+err.Error())
                return
        }
 
        csu, err := a.coreService.GetComputeClusterUserByPair(ctx, cluster.ID, 
user.ID) // TODO: use this to get the local username for the association 
instead of assuming it's the same as the Airavata Custos username
        if err != nil {
                slog.Error("Failed to get compute cluster user by pair", 
"error", err)
+               a.recordAuditEvent("ComputeAllocationMembershipCreationFailed", 
membership.ID, "Failed to get compute cluster user by pair. Error: 
"+err.Error())
                return
        }
 
        resources, err := a.coreService.ListResourcesForAllocation(ctx, 
allocation.ID) // TODO: use this to get the partition for the association 
instead of hardcoding it to "default"
        if err != nil {
                slog.Error("Failed to list resources for allocation", "error", 
err)
+               a.recordAuditEvent("ComputeAllocationMembershipCreationFailed", 
membership.ID, "Failed to list resources for allocation. Error: "+err.Error())
                return
        }
 
@@ -56,14 +61,16 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationMembershipCreation(
                Account:   allocation.Name,
                Cluster:   cluster.Name,
                User:      csu.LocalUsername,
-               Partition: resources[0].Name,
+               Partition: resources[0].Name, // TODO: do for each resource
        }
 
        err = a.slurmClient.UpsertAssociation(association)
        if err != nil {
                slog.Error("Failed to upsert association", "error", err)
+               a.recordAuditEvent("ComputeAllocationMembershipCreationFailed", 
membership.ID, "Failed to upsert association. Error: "+err.Error())
        } else {
                slog.Info("Successfully upserted association", "association", 
association)
+               
a.recordAuditEvent("ComputeAllocationMembershipCreationSucceeded", 
membership.ID, "Successfully upserted association.")
        }
 }
 
@@ -78,12 +85,14 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationMembershipResourceOv
        membership, err := a.coreService.GetComputeAllocationMembership(ctx, 
override.ComputeAllocationMembershipID)
        if err != nil {
                slog.Error("Failed to get compute allocation membership for 
resource override creation", "error", err)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationFailed", 
override.ID, "Failed to get compute allocation membership. Error: "+err.Error())
                return
        }
 
        allocationResource, err := 
a.coreService.GetComputeAllocationResource(ctx, 
override.ComputeAllocationResourceID)
        if err != nil {
                slog.Error("Failed to get compute allocation resource for 
resource override creation", "error", err)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationFailed", 
override.ID, "Failed to get compute allocation resource. Error: "+err.Error())
                return
        }
 
@@ -93,24 +102,28 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationMembershipResourceOv
        allocation, err := a.coreService.GetComputeAllocation(ctx, 
membership.ComputeAllocationID)
        if err != nil {
                slog.Error("Failed to get compute allocation", "error", err)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationFailed", 
override.ID, "Failed to get compute allocation. Error: "+err.Error())
                return
        }
 
        cluster, err := a.coreService.GetComputeCluster(ctx, 
allocation.ComputeClusterID)
        if err != nil {
                slog.Error("Failed to get compute cluster", "error", err)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationFailed", 
override.ID, "Failed to get compute cluster. Error: "+err.Error())
                return
        }
 
        user, err := a.coreService.GetUser(ctx, membership.UserID)
        if err != nil {
                slog.Error("Failed to get user", "error", err)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationFailed", 
override.ID, "Failed to get user. Error: "+err.Error())
                return
        }
 
        csu, err := a.coreService.GetComputeClusterUserByPair(ctx, cluster.ID, 
user.ID) // TODO: use this to get the local username for the association 
instead of assuming it's the same as the Airavata Custos username
        if err != nil {
                slog.Error("Failed to get compute cluster user by pair", 
"error", err)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationFailed", 
override.ID, "Failed to get compute cluster user by pair. Error: "+err.Error())
                return
        }
 
@@ -148,7 +161,9 @@ func (a *AssociationSubscriber) 
SubscribeToComputeAllocationMembershipResourceOv
        err = a.slurmClient.UpsertAssociation(association)
        if err != nil {
                slog.Error("Failed to upsert association for membership 
resource override creation", "error", err)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationFailed", 
override.ID, "Failed to upsert association. Error: "+err.Error())
        } else {
                slog.Info("Successfully upserted association for membership 
resource override creation", "association", association)
+               
a.recordAuditEvent("ComputeAllocationMembershipResourceOverrideCreationSucceeded",
 override.ID, "Successfully upserted association.")
        }
 }
diff --git 
a/connectors/SLURM/Association-Mapper/internal/subscribers/members_integration_test.go
 
b/connectors/SLURM/Association-Mapper/internal/subscribers/members_integration_test.go
new file mode 100644
index 000000000..58ada869c
--- /dev/null
+++ 
b/connectors/SLURM/Association-Mapper/internal/subscribers/members_integration_test.go
@@ -0,0 +1,117 @@
+package subscribers
+
+import (
+       "os"
+       "testing"
+       "context"
+       
"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"
+)
+
+func TestSubscribeToComputeAllocationMembershipCreation(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"
+       computeAllocationID := "compute-allocation-001"
+       computeAllocationName := "MD Allocation"
+       partitionName := "compute"
+       allocationResourceId := "allocation-resource-001"
+       //allocationMappingId := "allocation-mapping-001"
+       orgName := "Georgia Institute of Technology"
+       localUsername := "testuser" // testuser, testuser2, and testuser3 are 
the 3 users in the test cluster
+
+       client.CreateAccount(operations.Account{
+               Name:         computeAllocationName,
+               Description:  "Test account for integration testing",
+               Organization: orgName,
+       }, clusterName)
+
+       client.UpsertAssociation(operations.Association{
+               Account:   computeAllocationName,
+               Cluster:   clusterName,
+               Partition: partitionName,
+               Limits: operations.AssocLimits{
+                       GrpTRES: []operations.TRES{
+                               {
+                                       Type:  "cpu",
+                                       Count: 100,
+                               },
+                       },
+                       GrpTRESMins: []operations.TRES{
+                               {
+                                       Type:  "cpu",
+                                       Count: 1000,
+                               },
+                       },
+               },
+       })
+
+       defer client.DeleteAccount(computeAllocationName)
+
+       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: orgName}, 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
+               },
+               GetComputeClusterUserByPairFunc: func(ctx context.Context, 
clusterID, userID string) (*models.ComputeClusterUser, error) {
+                       return &models.ComputeClusterUser{ID: "csu-001", 
LocalUsername: localUsername}, nil
+               },
+               ListResourcesForAllocationFunc: func(ctx context.Context, 
allocationID string) ([]models.ComputeAllocationResource, error) {
+                       return []models.ComputeAllocationResource{
+                               {ID: allocationResourceId, Name: partitionName, 
ResourceType: "cpu", ResourceAmount: 1000},
+                       }, nil
+               },
+       }
+
+       // In the test cluster, there are 3 users: testuser, testuser2, and 
testuser3
+
+       membership := &models.ComputeAllocationMembership{
+               ID:                  "membership-001",
+               UserID:              "user-001",
+               ComputeAllocationID: computeAllocationID,
+       }
+       associationSubscriber := NewAssociationSubscriber(client, nil, 
mockCoreService)
+       
associationSubscriber.SubscribeToComputeAllocationMembershipCreation(*membership)
+
+       if len(auditEvents) != 1 {
+               t.Fatalf("Expected 1 audit event, but got %d", len(auditEvents))
+       }
+
+       if auditEvents[0].EventType != 
"ComputeAllocationMembershipCreationSucceeded" {
+               t.Fatalf("Expected audit event type 
'ComputeAllocationMembershipCreationSucceeded', but got '%s'", 
auditEvents[0].EventType)
+       }
+}
diff --git 
a/connectors/SLURM/Association-Mapper/internal/subscribers/subscriber.go 
b/connectors/SLURM/Association-Mapper/internal/subscribers/subscriber.go
index 96f83a832..3a2fa5161 100644
--- a/connectors/SLURM/Association-Mapper/internal/subscribers/subscriber.go
+++ b/connectors/SLURM/Association-Mapper/internal/subscribers/subscriber.go
@@ -1,8 +1,14 @@
 package subscribers
 
-import client 
"github.com/apache/airavata-custos/connectors/SLURM/Association-Mapper/internal/operations"
-import "github.com/apache/airavata-custos/pkg/events"
-import "github.com/apache/airavata-custos/pkg/service"
+import (
+       "context"
+       "time"
+
+       client 
"github.com/apache/airavata-custos/connectors/SLURM/Association-Mapper/internal/operations"
+       "github.com/apache/airavata-custos/pkg/events"
+       "github.com/apache/airavata-custos/pkg/models"
+       "github.com/apache/airavata-custos/pkg/service"
+)
 
 type AssociationSubscriber struct {
        slurmClient *client.Client
@@ -26,3 +32,13 @@ func (a *AssociationSubscriber) RegisterSubscribers() {
        
a.eventBus.SubscribeComputeAllocationMembershipResourceOverrideCreated(a.SubscribeToComputeAllocationMembershipResourceOverrideCreation)
        
a.eventBus.SubscribeComputeAllocationResourceMappingCreated(a.SubscribeToComputeAllocationResourceMappingCreation)
 }
+
+func (a *AssociationSubscriber) recordAuditEvent(eventType, entityId, message 
string) {
+       auditEvent := &models.AuditEvent{
+               EventType: eventType,
+               EntityID:  entityId,
+               Details:   message,
+               EventTime: time.Now(),
+       }
+       a.coreService.CreateAuditEvent(context.Background(), auditEvent)
+}

Reply via email to