(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func 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 | |
| 71 | func TestAPIUnlock(t *testing.T) { |
| 72 | require.NotNil(t, delReqSchema) |
nothing calls this directly
no test coverage detected