mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-08 00:57:24 +00:00
50 lines
1.4 KiB
Go
50 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, objectIdentifier := NewOrganizationAuditEvent(nil)
|
|
routableObjectIdentifier := NewRoutableIdentifier(objectIdentifier)
|
|
|
|
// Test
|
|
t.Run("Log", func(t *testing.T) {
|
|
assert.Nil(t, (*auditApi).Log(
|
|
context.Background(), event, auditV1.Visibility_VISIBILITY_PUBLIC, routableObjectIdentifier))
|
|
})
|
|
|
|
t.Run("ValidateAndSerialize", func(t *testing.T) {
|
|
visibility := auditV1.Visibility_VISIBILITY_PUBLIC
|
|
cloudEvent, err := (*auditApi).ValidateAndSerializeWithTrace(
|
|
event, visibility, routableObjectIdentifier, nil, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
validateRoutableEventPayload(
|
|
t, cloudEvent.Data, objectIdentifier, event, event.ProtoPayload.MethodName, visibility)
|
|
})
|
|
|
|
t.Run("ValidateAndSerialize event nil", func(t *testing.T) {
|
|
visibility := auditV1.Visibility_VISIBILITY_PUBLIC
|
|
_, err := (*auditApi).ValidateAndSerialize(nil, visibility, routableObjectIdentifier)
|
|
|
|
assert.ErrorIs(t, err, ErrEventNil)
|
|
})
|
|
|
|
t.Run("Send", func(t *testing.T) {
|
|
var cloudEvent = CloudEvent{}
|
|
|
|
assert.Nil(t, (*auditApi).Send(context.Background(), routableObjectIdentifier, &cloudEvent))
|
|
})
|
|
}
|