Add audit event tests for callback_handler

This commit is contained in:
Joshua Casey
2024-11-01 12:25:55 -05:00
parent 4df043a91c
commit dd56f2b47f
3 changed files with 175 additions and 67 deletions

View File

@@ -27,13 +27,13 @@ type WantedAuditLog struct {
Params map[string]any
}
func WantAuditLog(message string, params map[string]any, auditID string) WantedAuditLog {
func WantAuditLog(message string, params map[string]any, auditID ...string) WantedAuditLog {
result := WantedAuditLog{
Message: message,
Params: params,
}
if auditID != "" {
result.Params["auditID"] = auditID
if len(auditID) > 0 {
result.Params["auditID"] = auditID[0]
}
return result
}
@@ -41,6 +41,12 @@ func WantAuditLog(message string, params map[string]any, auditID string) WantedA
func CompareAuditLogs(t *testing.T, wantAuditLogs []WantedAuditLog, actualAuditLogsOneLiner string) {
t.Helper()
// There are tests that verify that no audit events were emitted
if len(wantAuditLogs) == 0 {
require.Empty(t, actualAuditLogsOneLiner, "no audit events were expected, but some were found")
return
}
wantJsonAuditLogs := make([]map[string]any, 0)
wantMessages := make([]string, 0)
for _, wantAuditLog := range wantAuditLogs {