Skip to content

Commit 6b84a1d

Browse files
sapklunny
authored andcommitted
lfs/lock: round locked_at timestamp to second (#7872) (#7875)
* lfs/lock: round locked_at timestamp to second * test returned locked_at values * tests: use time RFC3339
1 parent 68424ed commit 6b84a1d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

integrations/api_repo_lfs_locks_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ func TestAPILFSLocksLogged(t *testing.T) {
104104
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks", test.repo.FullName()), map[string]string{"path": test.path})
105105
req.Header.Set("Accept", "application/vnd.git-lfs+json")
106106
req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
107-
session.MakeRequest(t, req, test.httpResult)
107+
resp := session.MakeRequest(t, req, test.httpResult)
108108
if len(test.addTime) > 0 {
109+
var lfsLock api.LFSLockResponse
110+
DecodeJSON(t, resp, &lfsLock)
111+
assert.EqualValues(t, lfsLock.Lock.LockedAt.Format(time.RFC3339), lfsLock.Lock.LockedAt.Format(time.RFC3339Nano)) //locked at should be rounded to second
109112
for _, id := range test.addTime {
110113
resultsTests[id].locksTimes = append(resultsTests[id].locksTimes, time.Now())
111114
}
@@ -124,6 +127,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
124127
for i, lock := range lfsLocks.Locks {
125128
assert.EqualValues(t, test.locksOwners[i].DisplayName(), lock.Owner.Name)
126129
assert.WithinDuration(t, test.locksTimes[i], lock.LockedAt, 3*time.Second)
130+
assert.EqualValues(t, lock.LockedAt.Format(time.RFC3339), lock.LockedAt.Format(time.RFC3339Nano)) //locked at should be rounded to second
127131
}
128132

129133
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks/verify", test.repo.FullName()), map[string]string{})

models/lfs_lock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (l *LFSLock) APIFormat() *api.LFSLock {
5656
return &api.LFSLock{
5757
ID: strconv.FormatInt(l.ID, 10),
5858
Path: l.Path,
59-
LockedAt: l.Created,
59+
LockedAt: l.Created.Round(time.Second),
6060
Owner: &api.LFSLockOwner{
6161
Name: l.Owner.DisplayName(),
6262
},

0 commit comments

Comments
 (0)