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

Function TestVerifySuccess

tq/verify_test.go:26–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestVerifySuccess(t *testing.T) {
27 var called uint32
28 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
29 if r.URL.String() != "/verify" {
30 w.WriteHeader(http.StatusNotFound)
31 return
32 }
33
34 atomic.AddUint32(&called, 1)
35
36 assert.Equal(t, "POST", r.Method)
37 assert.Equal(t, "bar", r.Header.Get("Foo"))
38 assert.Equal(t, "29", r.Header.Get("Content-Length"))
39 assert.Equal(t, "application/vnd.git-lfs+json", r.Header.Get("Content-Type"))
40
41 var tr Transfer
42 assert.Nil(t, json.NewDecoder(r.Body).Decode(&tr))
43 assert.Equal(t, "abcd1234", tr.Oid)
44 assert.EqualValues(t, 123, tr.Size)
45 }))
46 defer srv.Close()
47
48 // Set auth on the server URL but not on the /verify endpoint. Since auth
49 // will cause the request to fail, this will test that the correct access
50 // mode is being passed to `DoWithAuth()`
51 c, err := lfsapi.NewClient(lfshttp.NewContext(nil, nil, map[string]string{
52 "lfs.transfer.maxverifies": "1",
53 "lfs." + srv.URL + ".access": "Basic",
54 "lfs." + srv.URL + "/verify.access": "None",
55 }))
56 require.Nil(t, err)
57 tr := &Transfer{
58 Oid: "abcd1234",
59 Size: 123,
60 Actions: map[string]*Action{
61 "verify": &Action{
62 Href: srv.URL + "/verify",
63 Header: map[string]string{
64 "foo": "bar",
65 },
66 },
67 },
68 }
69
70 assert.Nil(t, verifyUpload(c, "origin", tr))
71 assert.EqualValues(t, 1, called)
72}

Callers

nothing calls this directly

Calls 7

NewClientFunction · 0.92
NewContextFunction · 0.92
verifyUploadFunction · 0.85
StringMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected