test: Add LogAuditEvent tests

Cover success and failure logging branches (66.7% to 100%)
This commit is contained in:
rcourtman 2025-12-02 01:46:27 +00:00
parent 8f42156781
commit 24fbce1281

View file

@ -1036,3 +1036,36 @@ func TestSecurityHeadersWithConfig_NextHandlerCalled(t *testing.T) {
t.Error("next handler was not called")
}
}
func TestLogAuditEvent_Success(t *testing.T) {
// Should not panic and should log at Info level
LogAuditEvent(
"test_event",
"testuser",
"192.168.1.100",
"/api/test",
true,
"test details",
)
// If we got here without panic, the test passes
}
func TestLogAuditEvent_Failure(t *testing.T) {
// Should not panic and should log at Warn level
LogAuditEvent(
"failed_login",
"attacker",
"203.0.113.42",
"/api/login",
false,
"invalid credentials",
)
// If we got here without panic, the test passes
}
func TestLogAuditEvent_EmptyFields(t *testing.T) {
// Should handle empty strings gracefully
LogAuditEvent("", "", "", "", true, "")
LogAuditEvent("", "", "", "", false, "")
// If we got here without panic, the test passes
}