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

Function TestAPIUnlock

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

Source from the content-addressed store, hash-verified

69}
70
71func TestAPIUnlock(t *testing.T) {
72 require.NotNil(t, delReqSchema)
73 require.NotNil(t, createResSchema)
74
75 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
76 if r.URL.Path != "/api/locks/123/unlock" {
77 w.WriteHeader(404)
78 return
79 }
80
81 assert.Equal(t, "POST", r.Method)
82 assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept"))
83 assert.Equal(t, lfshttp.RequestContentType, r.Header.Get("Content-Type"))
84
85 reqLoader, body := gojsonschema.NewReaderLoader(r.Body)
86 unlockReq := &unlockRequest{}
87 err := json.NewDecoder(body).Decode(unlockReq)
88 r.Body.Close()
89 assert.Nil(t, err)
90 assert.True(t, unlockReq.Force)
91 assertSchema(t, delReqSchema, reqLoader)
92
93 w.Header().Set("Content-Type", "application/json")
94 resLoader, resWriter := gojsonschema.NewWriterLoader(w)
95 err = json.NewEncoder(resWriter).Encode(&unlockResponse{
96 Lock: &Lock{
97 Id: "123",
98 Path: "response",
99 },
100 })
101 assert.Nil(t, err)
102 assertSchema(t, createResSchema, resLoader)
103 }))
104 defer srv.Close()
105
106 c, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
107 "lfs.url": srv.URL + "/api",
108 }))
109 require.Nil(t, err)
110
111 lc := &httpLockClient{Client: c}
112 unlockRes, status, err := lc.Unlock(&git.Ref{
113 Name: "master",
114 Sha: "6161616161616161616161616161616161616161",
115 Type: git.RefTypeLocalBranch,
116 }, "", "123", true)
117 require.Nil(t, err)
118 assert.Equal(t, 200, status)
119 assert.Equal(t, "123", unlockRes.Lock.Id)
120 assert.Equal(t, "response", unlockRes.Lock.Path)
121}
122
123func TestAPISearch(t *testing.T) {
124 require.NotNil(t, listResSchema)

Callers

nothing calls this directly

Calls 9

UnlockMethod · 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