Skip to content

Commit 61606fc

Browse files
committed
Add delete test + fix
1 parent 18eed10 commit 61606fc

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

integrations/api_repo_lfs_locks_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package integrations
66

77
import (
8-
"fmt"
98
"io/ioutil"
109
"net/http"
1110
"strings"
@@ -97,7 +96,6 @@ func TestAPILFSLocksLogged(t *testing.T) {
9796
req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
9897
req.Body = ioutil.NopCloser(strings.NewReader("{}"))
9998
resp = session.MakeRequest(t, req, http.StatusOK)
100-
fmt.Println(string(resp.Body))
10199
var lfsLocksVerify api.LFSLockListVerify
102100
DecodeJSON(t, resp, &lfsLocksVerify)
103101
assert.Len(t, lfsLocksVerify.Ours, 2)
@@ -106,4 +104,21 @@ func TestAPILFSLocksLogged(t *testing.T) {
106104
assert.EqualValues(t, user.DisplayName(), lock.Owner.Name)
107105
}
108106

107+
req = NewRequestf(t, "POST", "/%s/%s/info/lfs/locks/%s/unlock", user.Name, repo.Name, lfsLocksVerify.Ours[0].ID)
108+
req.Header.Set("Accept", "application/vnd.git-lfs+json")
109+
req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
110+
req.Body = ioutil.NopCloser(strings.NewReader("{}"))
111+
resp = session.MakeRequest(t, req, http.StatusOK)
112+
var lfsLockRep api.LFSLockResponse
113+
DecodeJSON(t, resp, &lfsLockRep)
114+
assert.Equal(t, lfsLocksVerify.Ours[0].ID, lfsLockRep.Lock.ID)
115+
assert.Equal(t, user.DisplayName(), lfsLockRep.Lock.Owner.Name)
116+
117+
req = NewRequestf(t, "GET", "/%s/%s/info/lfs/locks", user.Name, repo.Name)
118+
req.Header.Set("Accept", "application/vnd.git-lfs+json")
119+
req.Header.Set("Content-Type", "application/vnd.git-lfs+json")
120+
resp = session.MakeRequest(t, req, http.StatusOK)
121+
DecodeJSON(t, resp, &lfsLocks)
122+
assert.Len(t, lfsLocks.Locks, 1)
123+
109124
}

models/lfs_lock.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,23 @@ func GetLFSLockByRepoID(repoID int64) (locks []*LFSLock, err error) {
130130
}
131131

132132
// DeleteLFSLockByID deletes a lock by given ID.
133-
func DeleteLFSLockByID(id int64, u *User, force bool) error {
134-
133+
func DeleteLFSLockByID(id int64, u *User, force bool) (*LFSLock, error) {
135134
lock, err := GetLFSLockByID(id)
136135
if err != nil {
137-
return err
136+
return nil, err
138137
}
139138

140139
err = CheckLFSAccessForRepo(u, lock.RepoID, "delete")
141140
if err != nil {
142-
return err
141+
return nil, err
143142
}
144143

145144
if !force && u.ID != lock.OwnerID {
146-
return fmt.Errorf("user doesn't own lock and force flag is not set")
145+
return nil, fmt.Errorf("user doesn't own lock and force flag is not set")
147146
}
148147

149148
_, err = x.ID(id).Delete(new(LFSLock))
150-
return err
149+
return lock, err
151150
}
152151

153152
//CheckLFSAccessForRepo check needed access mode base on action

modules/lfs/locks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func UnLockHandler(ctx *context.Context) {
215215
return
216216
}
217217

218-
err = models.DeleteLFSLockByID(ctx.ParamsInt64("id"), ctx.User, req.Force)
218+
lock, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.User, req.Force)
219219
if err != nil {
220220
if models.IsErrLFSLockUnauthorizedAction(err) {
221221
ctx.JSON(403, api.LFSLockError{
@@ -228,5 +228,5 @@ func UnLockHandler(ctx *context.Context) {
228228
})
229229
return
230230
}
231-
ctx.JSON(404, api.LFSLockError{Message: "Not found"})
231+
ctx.JSON(200, api.LFSLockResponse{Lock: lock.APIFormat()})
232232
}

routers/routes/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ func RegisterRoutes(m *macaron.Macaron) {
690690
m.Get("/", lfs.GetListLockHandler)
691691
m.Post("/", lfs.PostLockHandler)
692692
m.Post("/verify", lfs.VerifyLockHandler)
693-
m.Post("/:id/unlock", lfs.UnLockHandler)
693+
m.Post("/:lid/unlock", lfs.UnLockHandler)
694694
}, context.RepoAssignment())
695695
m.Any("/*", func(ctx *context.Context) {
696696
ctx.Handle(404, "", nil)

0 commit comments

Comments
 (0)