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

Function TestAPISearch

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

Source from the content-addressed store, hash-verified

121}
122
123func TestAPISearch(t *testing.T) {
124 require.NotNil(t, listResSchema)
125
126 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
127 if r.URL.Path != "/api/locks" {
128 w.WriteHeader(404)
129 return
130 }
131
132 assert.Equal(t, "GET", r.Method)
133 assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept"))
134 assert.Equal(t, "", r.Header.Get("Content-Type"))
135
136 q := r.URL.Query()
137 assert.Equal(t, "A", q.Get("a"))
138 assert.Equal(t, "cursor", q.Get("cursor"))
139 assert.Equal(t, "5", q.Get("limit"))
140
141 w.Header().Set("Content-Type", "application/json")
142 resLoader, resWriter := gojsonschema.NewWriterLoader(w)
143 err := json.NewEncoder(resWriter).Encode(&lockList{
144 Locks: []Lock{
145 {Id: "1"},
146 {Id: "2"},
147 },
148 })
149 assert.Nil(t, err)
150 assertSchema(t, listResSchema, resLoader)
151 }))
152 defer srv.Close()
153
154 c, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
155 "lfs.url": srv.URL + "/api",
156 }))
157 require.Nil(t, err)
158
159 lc := &httpLockClient{Client: c}
160 locks, status, err := lc.Search("", &lockSearchRequest{
161 Filters: []lockFilter{
162 {Property: "a", Value: "A"},
163 },
164 Cursor: "cursor",
165 Limit: 5,
166 })
167 require.Nil(t, err)
168 assert.Equal(t, 200, status)
169 assert.Equal(t, 2, len(locks.Locks))
170 assert.Equal(t, "1", locks.Locks[0].Id)
171 assert.Equal(t, "2", locks.Locks[1].Id)
172}
173
174func TestAPISearchVerifiable(t *testing.T) {
175 require.NotNil(t, verifyResSchema)

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected