Browse Source

lfs/lock: round locked_at timestamp to second (#7872)

* lfs/lock: round locked_at timestamp to second

* test returned locked_at values

* tests: use time RFC3339
tags/v1.10.0-rc1
Antoine GIRARD 4 years ago
parent
commit
c2c35d169c
2 changed files with 6 additions and 2 deletions
  1. 5
    1
      integrations/api_repo_lfs_locks_test.go
  2. 1
    1
      models/lfs_lock.go

+ 5
- 1
integrations/api_repo_lfs_locks_test.go View File

req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks", test.repo.FullName()), map[string]string{"path": test.path}) req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks", test.repo.FullName()), map[string]string{"path": test.path})
req.Header.Set("Accept", "application/vnd.git-lfs+json") req.Header.Set("Accept", "application/vnd.git-lfs+json")
req.Header.Set("Content-Type", "application/vnd.git-lfs+json") req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
session.MakeRequest(t, req, test.httpResult)
resp := session.MakeRequest(t, req, test.httpResult)
if len(test.addTime) > 0 { if len(test.addTime) > 0 {
var lfsLock api.LFSLockResponse
DecodeJSON(t, resp, &lfsLock)
assert.EqualValues(t, lfsLock.Lock.LockedAt.Format(time.RFC3339), lfsLock.Lock.LockedAt.Format(time.RFC3339Nano)) //locked at should be rounded to second
for _, id := range test.addTime { for _, id := range test.addTime {
resultsTests[id].locksTimes = append(resultsTests[id].locksTimes, time.Now()) resultsTests[id].locksTimes = append(resultsTests[id].locksTimes, time.Now())
} }
for i, lock := range lfsLocks.Locks { for i, lock := range lfsLocks.Locks {
assert.EqualValues(t, test.locksOwners[i].DisplayName(), lock.Owner.Name) assert.EqualValues(t, test.locksOwners[i].DisplayName(), lock.Owner.Name)
assert.WithinDuration(t, test.locksTimes[i], lock.LockedAt, 3*time.Second) assert.WithinDuration(t, test.locksTimes[i], lock.LockedAt, 3*time.Second)
assert.EqualValues(t, lock.LockedAt.Format(time.RFC3339), lock.LockedAt.Format(time.RFC3339Nano)) //locked at should be rounded to second
} }


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

+ 1
- 1
models/lfs_lock.go View File

return &api.LFSLock{ return &api.LFSLock{
ID: strconv.FormatInt(l.ID, 10), ID: strconv.FormatInt(l.ID, 10),
Path: l.Path, Path: l.Path,
LockedAt: l.Created,
LockedAt: l.Created.Round(time.Second),
Owner: &api.LFSLockOwner{ Owner: &api.LFSLockOwner{
Name: l.Owner.DisplayName(), Name: l.Owner.DisplayName(),
}, },

Loading…
Cancel
Save