Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps committed Jun 8, 2024
1 parent a673da3 commit fd16120
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
25 changes: 14 additions & 11 deletions internal/server/audit/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
16 changes: 10 additions & 6 deletions internal/server/audit/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
})

Expand All @@ -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) {
Expand Down Expand Up @@ -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),
},
})

Expand All @@ -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])
})
}
}

0 comments on commit fd16120

Please sign in to comment.