From fd1612069901900853c2d5d0b6039941a79394a7 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Sat, 8 Jun 2024 17:22:44 -0400 Subject: [PATCH] chore: fix tests Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com> --- internal/server/audit/events_test.go | 25 ++++++++++++++----------- internal/server/audit/log/log_test.go | 16 ++++++++++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/internal/server/audit/events_test.go b/internal/server/audit/events_test.go index ef939914c3..becfbd7e2e 100644 --- a/internal/server/audit/events_test.go +++ b/internal/server/audit/events_test.go @@ -9,19 +9,22 @@ import ( ) func TestMarshalLogObject(t *testing.T) { - actor := Actor{Authentication: "github"} - e := Event{ - Version: "0.1", - Type: "sometype", - Action: "modified", - Metadata: Metadata{Actor: &actor}, - Payload: "custom payload", - } - enc := zapcore.NewMapObjectEncoder() - err := e.MarshalLogObject(enc) + var ( + actor = Actor{Authentication: "github"} + e = Event{ + Version: "0.2", + Type: "sometype", + Action: "modified", + Metadata: Metadata{Actor: &actor}, + Payload: "custom payload", + } + enc = zapcore.NewMapObjectEncoder() + err = e.MarshalLogObject(enc) + ) + require.NoError(t, err) assert.Equal(t, map[string]any{ - "version": "0.1", + "version": "0.2", "action": "modified", "type": "sometype", "metadata": Metadata{Actor: &actor}, diff --git a/internal/server/audit/log/log_test.go b/internal/server/audit/log/log_test.go index af8619537b..3edd9aa7b7 100644 --- a/internal/server/audit/log/log_test.go +++ b/internal/server/audit/log/log_test.go @@ -33,14 +33,16 @@ func TestSink(t *testing.T) { err = s.SendAudits(context.TODO(), []audit.Event{ { - Version: "0.1", + Version: "0.2", Type: string(flipt.SubjectFlag), Action: string(flipt.ActionCreate), + Status: string(flipt.StatusSuccess), }, { - Version: "0.1", + Version: "0.2", Type: string(flipt.SubjectConstraint), Action: string(flipt.ActionUpdate), + Status: string(flipt.StatusSuccess), }, }) @@ -58,7 +60,7 @@ func TestSink(t *testing.T) { assert.NotEmpty(t, lines) assert.NotEmpty(t, lines[0]) - assert.JSONEq(t, `{"version": "0.1", "type": "flag", "action": "create", "metadata": {}, "payload": null, "timestamp": ""}`, lines[0]) + assert.JSONEq(t, `{"version": "0.2", "type": "flag", "action": "create", "metadata": {}, "payload": null, "timestamp": "", "status": "success"}`, lines[0]) } func TestSink_DirNotExists(t *testing.T) { @@ -87,14 +89,16 @@ func TestSink_DirNotExists(t *testing.T) { err = s.SendAudits(context.TODO(), []audit.Event{ { - Version: "0.1", + Version: "0.2", Type: string(flipt.SubjectFlag), Action: string(flipt.ActionCreate), + Status: string(flipt.StatusSuccess), }, { - Version: "0.1", + Version: "0.2", Type: string(flipt.SubjectConstraint), Action: string(flipt.ActionUpdate), + Status: string(flipt.StatusSuccess), }, }) @@ -113,7 +117,7 @@ func TestSink_DirNotExists(t *testing.T) { assert.NotEmpty(t, lines) assert.NotEmpty(t, lines[0]) - assert.JSONEq(t, `{"version": "0.1", "type": "flag", "action": "create", "metadata": {}, "payload": null, "timestamp": ""}`, lines[0]) + assert.JSONEq(t, `{"version": "0.2", "type": "flag", "action": "create", "metadata": {}, "payload": null, "timestamp": "", "status": "success"}`, lines[0]) }) } }