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

Function TestStatsWithoutKey

lfshttp/stats_test.go:83–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestStatsWithoutKey(t *testing.T) {
84 var called uint32
85 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
86 atomic.AddUint32(&called, 1)
87 t.Logf("srv req %s %s", r.Method, r.URL.Path)
88 assert.Equal(t, "POST", r.Method)
89
90 assert.Equal(t, "Basic ABC", r.Header.Get("Authorization"))
91 body := &verboseTest{}
92 err := json.NewDecoder(r.Body).Decode(body)
93 assert.Nil(t, err)
94 assert.Equal(t, "Verbose", body.Test)
95 w.Header().Set("Content-Type", "application/json")
96 w.Write([]byte(`{"Status":"Ok"}`))
97 }))
98 defer srv.Close()
99
100 out := &bytes.Buffer{}
101 c, _ := NewClient(nil)
102 c.ConcurrentTransfers = 5
103 c.LogHTTPStats(nopCloser(out))
104
105 req, err := http.NewRequest("POST", srv.URL, nil)
106 req.Header.Set("Authorization", "Basic ABC")
107 req.Header.Set("Content-Type", "application/json")
108 require.Nil(t, err)
109 require.Nil(t, MarshalToRequest(req, verboseTest{"Verbose"}))
110
111 res, err := c.Do(req)
112 require.Nil(t, err)
113 io.Copy(io.Discard, res.Body)
114 res.Body.Close()
115 assert.Nil(t, c.Close())
116
117 assert.Equal(t, 200, res.StatusCode)
118 assert.EqualValues(t, 1, called)
119
120 stats := strings.TrimSpace(out.String())
121 t.Log(stats)
122 assert.True(t, strings.Contains(stats, "concurrent=5"))
123 assert.Equal(t, 1, len(strings.Split(stats, "\n")))
124}
125
126func TestStatsDisabled(t *testing.T) {
127 var called uint32

Callers

nothing calls this directly

Calls 15

LogHTTPStatsMethod · 0.95
DoMethod · 0.95
CloseMethod · 0.95
nopCloserFunction · 0.85
LogfMethod · 0.80
LogMethod · 0.80
NewClientFunction · 0.70
MarshalToRequestFunction · 0.70
GetMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected