Skip to content

Commit

Permalink
Round times to the nearest second and chop nanos
Browse files Browse the repository at this point in the history
Clockwork changed to defaulting to the current time rather than a fixed
time. This means that the nanoseconds field is now set which isn't the
case in the MySQL timestamp. The value returned from MySQL is always
going to be limited to the nearest second but the value in Go that is
expected will have nanosecond precision. We need to chop it off.
  • Loading branch information
jrozner committed May 4, 2023
1 parent a7b7802 commit a7db914
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/services/evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"io"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/theparanoids/ashirt-server/backend/contentstore"
Expand Down Expand Up @@ -381,7 +382,7 @@ func validateReadEvidenceOutput(t *testing.T, expected models.Evidence, actual *
require.Equal(t, expected.UUID, actual.UUID)
require.Equal(t, expected.Description, actual.Description)
require.Equal(t, expected.ContentType, actual.ContentType)
require.Equal(t, expected.OccurredAt, actual.OccurredAt)
require.Equal(t, expected.OccurredAt.Round(time.Second).UTC(), actual.OccurredAt)
}

func validateInsertedEvidence(t *testing.T, evi *dtos.Evidence, src services.CreateEvidenceInput,
Expand Down
4 changes: 2 additions & 2 deletions backend/services/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func TestUpdateTag(t *testing.T) {
OperationID: op.ID,
Name: "Moon",
ColorName: "green",
CreatedAt: TagEarth.CreatedAt,
CreatedAt: TagEarth.CreatedAt.Round(time.Second).UTC(),
UpdatedAt: updatedTag.UpdatedAt,
}, updatedTag)
})
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestUpdateDefaultTag(t *testing.T) {
ID: tagToUpdate.ID,
Name: i.Name,
ColorName: i.ColorName,
CreatedAt: tagToUpdate.CreatedAt,
CreatedAt: tagToUpdate.CreatedAt.Round(time.Second).UTC(),
UpdatedAt: updatedTag.UpdatedAt,
}, updatedTag)
})
Expand Down

0 comments on commit a7db914

Please sign in to comment.