Fix a failing test due to time resolutions mismatch. (#221)

* Round generated expiration timestamps to the nearest second.
This commit is contained in:
Todd Knight authored and GitHub committed 2020-07-27 14:06:59 -07:00
1 parent 194db3a6d8
commit 25514fb553
2 files changed
+7 -2

No files matched your search

+3 -1
View File
@@ -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
}
+4 -1
View File
@@ -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")
})
}
}