(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestPreadRemoteUpstream(t *testing.T) { |
| 27 | // Setup |
| 28 | m := map[string][]string{} |
| 29 | key := "somekey" |
| 30 | expected := "expected-result" |
| 31 | peersTried := 0 |
| 32 | svr3 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 33 | peersTried++ |
| 34 | w.WriteHeader(http.StatusUnauthorized) |
| 35 | })) |
| 36 | defer svr3.Close() |
| 37 | svr2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 38 | peersTried++ |
| 39 | w.WriteHeader(http.StatusNotFound) |
| 40 | })) |
| 41 | defer svr2.Close() |
| 42 | svr1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 43 | peersTried++ |
| 44 | w.WriteHeader(http.StatusBadGateway) |
| 45 | })) |
| 46 | defer svr1.Close() |
| 47 | val := []string{svr1.URL, svr2.URL, svr3.URL} |
| 48 | m[key] = val |
| 49 | |
| 50 | svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 51 | if "?"+r.URL.RawQuery == query { |
| 52 | w.Header().Set("Content-Type", "application/octet-stream") |
| 53 | // nolint:errcheck |
| 54 | w.Write([]byte(expected)) |
| 55 | } else { |
| 56 | w.WriteHeader(http.StatusNotFound) |
| 57 | } |
| 58 | })) |
| 59 | defer svr.Close() |
| 60 | p := svr.URL + "/some-path" |
| 61 | u := "http://127.0.0.1:5000/blobs/" + p + query |
| 62 | req, err := http.NewRequest("GET", u, nil) |
| 63 | if err != nil { |
| 64 | t.Fatal(err) |
| 65 | } |
| 66 | |
| 67 | router := mocks.NewMockRouter(m) |
| 68 | c, _ := gin.CreateTestContext(httptest.NewRecorder()) |
| 69 | c.Request = req |
| 70 | c.Params = []gin.Param{ |
| 71 | {Key: "url", Value: p}, |
| 72 | } |
| 73 | |
| 74 | pc := pcontext.FromContext(c) |
| 75 | |
| 76 | pc.Set(pcontext.BlobUrlCtxKey, pcontext.BlobUrl(pc)) |
| 77 | pc.Set(pcontext.BlobRangeCtxKey, "bytes=0-10") |
| 78 | pc.Set(pcontext.FileChunkCtxKey, key) |
| 79 | |
| 80 | r := NewReader(pc, router, 3, 500*time.Millisecond, mr).(*reader) |
| 81 | b := make([]byte, 10) |
| 82 | |
| 83 | // Test |
nothing calls this directly
no test coverage detected