MCPcopy
hub / github.com/git-lfs/git-lfs / TestAPILock

Function TestAPILock

locking/api_test.go:21–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestAPILock(t *testing.T) {
22 require.NotNil(t, createReqSchema)
23 require.NotNil(t, createResSchema)
24
25 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
26 if r.URL.Path != "/api/locks" {
27 w.WriteHeader(404)
28 return
29 }
30
31 assert.Equal(t, "POST", r.Method)
32 assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept"))
33 assert.Equal(t, lfshttp.RequestContentType, r.Header.Get("Content-Type"))
34 assert.Equal(t, "53", r.Header.Get("Content-Length"))
35
36 reqLoader, body := gojsonschema.NewReaderLoader(r.Body)
37 lockReq := &lockRequest{}
38 err := json.NewDecoder(body).Decode(lockReq)
39 r.Body.Close()
40 assert.Nil(t, err)
41 assert.Equal(t, "refs/heads/master", lockReq.Ref.Name)
42 assert.Equal(t, "request", lockReq.Path)
43 assertSchema(t, createReqSchema, reqLoader)
44
45 w.Header().Set("Content-Type", "application/json")
46 resLoader, resWriter := gojsonschema.NewWriterLoader(w)
47 err = json.NewEncoder(resWriter).Encode(&lockResponse{
48 Lock: &Lock{
49 Id: "1",
50 Path: "response",
51 },
52 })
53 assert.Nil(t, err)
54 assertSchema(t, createResSchema, resLoader)
55 }))
56 defer srv.Close()
57
58 c, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
59 "lfs.url": srv.URL + "/api",
60 }))
61 require.Nil(t, err)
62
63 lc := &httpLockClient{Client: c}
64 lockRes, status, err := lc.Lock("", &lockRequest{Path: "request", Ref: &lockRef{Name: "refs/heads/master"}})
65 require.Nil(t, err)
66 assert.Equal(t, 200, status)
67 assert.Equal(t, "1", lockRes.Lock.Id)
68 assert.Equal(t, "response", lockRes.Lock.Path)
69}
70
71func TestAPIUnlock(t *testing.T) {
72 require.NotNil(t, delReqSchema)

Callers

nothing calls this directly

Calls 9

LockMethod · 0.95
NewClientFunction · 0.92
NewContextFunction · 0.92
EncodeMethod · 0.80
assertSchemaFunction · 0.70
GetMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected