(t *testing.T)
| 139 | } |
| 140 | |
| 141 | func TestFstatRemotePartialContent(t *testing.T) { |
| 142 | m := map[string][]string{} |
| 143 | |
| 144 | expected := "expected-result" |
| 145 | svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 146 | if "?"+r.URL.RawQuery == query { |
| 147 | w.Header().Set("Content-Type", "application/octet-stream") |
| 148 | // nolint:errcheck |
| 149 | w.WriteHeader(http.StatusPartialContent) |
| 150 | w.Header().Set("Content-Range", "bytes 0-10/10") |
| 151 | // nolint:errcheck |
| 152 | w.Write([]byte(expected)) |
| 153 | } else { |
| 154 | w.WriteHeader(http.StatusNotFound) |
| 155 | } |
| 156 | })) |
| 157 | defer svr.Close() |
| 158 | p := svr.URL + "/some-path" |
| 159 | u := "http://127.0.0.1:5000/blobs/" + p + query |
| 160 | req, err := http.NewRequest("GET", u, nil) |
| 161 | if err != nil { |
| 162 | t.Fatal(err) |
| 163 | } |
| 164 | |
| 165 | router := mocks.NewMockRouter(m) |
| 166 | c, _ := gin.CreateTestContext(httptest.NewRecorder()) |
| 167 | c.Request = req |
| 168 | c.Params = []gin.Param{ |
| 169 | {Key: "url", Value: p}, |
| 170 | } |
| 171 | |
| 172 | pc := pcontext.FromContext(c) |
| 173 | |
| 174 | pc.Set(pcontext.BlobUrlCtxKey, pcontext.BlobUrl(pc)) |
| 175 | pc.Set(pcontext.BlobRangeCtxKey, "bytes=0-0") |
| 176 | |
| 177 | r := NewReader(pc, router, 3, 500*time.Millisecond, mr).(*reader) |
| 178 | |
| 179 | got, err := r.FstatRemote() |
| 180 | if err != nil { |
| 181 | t.Fatal(err) |
| 182 | } else if got != int64(len(expected)) { |
| 183 | t.Fatalf("expected %v, got %v", len(expected), got) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | func TestP2pRetries(t *testing.T) { |
| 188 | l := zerolog.Nop() |
nothing calls this directly
no test coverage detected