mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-09 01:27:26 +00:00
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
auditV1 "dev.azure.com/schwarzit/schwarzit.stackit-core-platform/common-audit.git/gen/go/audit/v1"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMockAuditApi_Log(t *testing.T) {
|
|
|
|
auditApi, err := NewMockAuditApi()
|
|
assert.NoError(t, err)
|
|
|
|
// Instantiate test data
|
|
event, routingIdentifier, objectIdentifier := NewOrganizationAuditEvent(nil)
|
|
|
|
// Test
|
|
t.Run("Log", func(t *testing.T) {
|
|
assert.Nil(t, (*auditApi).Log(
|
|
context.Background(), event, auditV1.Visibility_VISIBILITY_PUBLIC, routingIdentifier, objectIdentifier))
|
|
})
|
|
|
|
t.Run("ValidateAndSerialize", func(t *testing.T) {
|
|
visibility := auditV1.Visibility_VISIBILITY_PUBLIC
|
|
serializedPayload, err := (*auditApi).ValidateAndSerialize(
|
|
event, visibility, routingIdentifier, objectIdentifier)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
validateProtobufMessagePayload(
|
|
t, serializedPayload.GetPayload(), routingIdentifier, objectIdentifier, event, event.EventName, visibility)
|
|
})
|
|
|
|
t.Run("ValidateAndSerialize event nil", func(t *testing.T) {
|
|
visibility := auditV1.Visibility_VISIBILITY_PUBLIC
|
|
_, err := (*auditApi).ValidateAndSerialize(nil, visibility, routingIdentifier, objectIdentifier)
|
|
|
|
assert.ErrorIs(t, err, ErrEventNil)
|
|
})
|
|
|
|
t.Run("Send", func(t *testing.T) {
|
|
var payload SerializedPayload = &routablePayload{}
|
|
|
|
assert.Nil(t, (*auditApi).Send(context.Background(), routingIdentifier, &payload))
|
|
})
|
|
}
|