diff --git a/internal/authtoken/repository.go b/internal/authtoken/repository.go index 1f8b526f1..320311ad4 100644 --- a/internal/authtoken/repository.go +++ b/internal/authtoken/repository.go @@ -86,7 +86,9 @@ func (r *Repository) CreateAuthToken(ctx context.Context, withIamUserId, withAut at.Token = token // TODO: Allow the caller to specify something different than the default duration. - expiration, err := ptypes.TimestampProto(time.Now().Add(maxTokenDuration)) + // We round the expiration time to the nearest second to make testing in different platforms with + // different time resolutions easier. + expiration, err := ptypes.TimestampProto(time.Now().Round(time.Second).Add(maxTokenDuration)) if err != nil { return nil, err } diff --git a/internal/authtoken/repository_test.go b/internal/authtoken/repository_test.go index 465030325..c8802e336 100644 --- a/internal/authtoken/repository_test.go +++ b/internal/authtoken/repository_test.go @@ -3,6 +3,7 @@ package authtoken import ( "context" "errors" + "sort" "testing" "time" @@ -575,7 +576,9 @@ func TestRepository_ListAuthTokens(t *testing.T) { return } assert.NoError(err) - assert.ElementsMatchf(tt.want, got, "row count") + sort.Slice(tt.want, func(i, j int) bool { return tt.want[i].PublicId < tt.want[j].PublicId }) + sort.Slice(got, func(i, j int) bool { return got[i].PublicId < got[j].PublicId }) + assert.Empty(cmp.Diff(tt.want, got, protocmp.Transform()), "row count") }) } }