Skip to content

Commit 53fc1d2

Browse files
committed
firewalldb: assert actions equal helper
Use a helper to compare Actions and prepare the timestamp comparisons so that they are ready for our SQL implementation of the Actions DB.
1 parent 2cb10d2 commit 53fc1d2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

firewalldb/actions_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestActionStorage(t *testing.T) {
7979
)
8080
require.NoError(t, err)
8181
require.Len(t, actions, 1)
82-
require.Equal(t, action1, actions[0])
82+
assertEqualActions(t, action1, actions[0])
8383

8484
actions, _, _, err = db.ListActions(
8585
ctx, nil,
@@ -100,7 +100,7 @@ func TestActionStorage(t *testing.T) {
100100
require.NoError(t, err)
101101
require.Len(t, actions, 1)
102102
action2.State = ActionStateDone
103-
require.Equal(t, action2, actions[0])
103+
assertEqualActions(t, action2, actions[0])
104104

105105
_, err = db.AddAction(ctx, action1)
106106
require.NoError(t, err)
@@ -132,7 +132,7 @@ func TestActionStorage(t *testing.T) {
132132
require.Len(t, actions, 1)
133133
action2.State = ActionStateError
134134
action2.ErrorReason = "fail whale"
135-
require.Equal(t, action2, actions[0])
135+
assertEqualActions(t, action2, actions[0])
136136
}
137137

138138
// TestListActions tests some ListAction options.
@@ -375,3 +375,17 @@ func TestListGroupActions(t *testing.T) {
375375
require.Equal(t, sessionID1, al[0].SessionID)
376376
require.Equal(t, sessionID2, al[1].SessionID)
377377
}
378+
379+
func assertEqualActions(t *testing.T, expected, got *Action) {
380+
expectedAttemptedAt := expected.AttemptedAt
381+
actualAttemptedAt := got.AttemptedAt
382+
383+
expected.AttemptedAt = time.Time{}
384+
got.AttemptedAt = time.Time{}
385+
386+
require.Equal(t, expected, got)
387+
require.Equal(t, expectedAttemptedAt.Unix(), actualAttemptedAt.Unix())
388+
389+
expected.AttemptedAt = expectedAttemptedAt
390+
got.AttemptedAt = actualAttemptedAt
391+
}

0 commit comments

Comments
 (0)