(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func TestFstatRemote(t *testing.T) { |
| 99 | m := map[string][]string{} |
| 100 | |
| 101 | expected := "expected-result" |
| 102 | svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 103 | if "?"+r.URL.RawQuery == query { |
| 104 | w.Header().Set("Content-Type", "application/octet-stream") |
| 105 | // nolint:errcheck |
| 106 | w.Write([]byte(expected)) |
| 107 | } else { |
| 108 | w.WriteHeader(http.StatusNotFound) |
| 109 | } |
| 110 | })) |
| 111 | defer svr.Close() |
| 112 | p := svr.URL + "/some-path" |
| 113 | u := "http://127.0.0.1:5000/blobs/" + p + query |
| 114 | req, err := http.NewRequest("GET", u, nil) |
| 115 | if err != nil { |
| 116 | t.Fatal(err) |
| 117 | } |
| 118 | |
| 119 | router := mocks.NewMockRouter(m) |
| 120 | c, _ := gin.CreateTestContext(httptest.NewRecorder()) |
| 121 | c.Request = req |
| 122 | c.Params = []gin.Param{ |
| 123 | {Key: "url", Value: p}, |
| 124 | } |
| 125 | |
| 126 | pc := pcontext.FromContext(c) |
| 127 | |
| 128 | pc.Set(pcontext.BlobUrlCtxKey, pcontext.BlobUrl(pc)) |
| 129 | pc.Set(pcontext.BlobRangeCtxKey, "bytes=0-0") |
| 130 | |
| 131 | r := NewReader(pc, router, 3, 500*time.Millisecond, mr).(*reader) |
| 132 | |
| 133 | got, err := r.FstatRemote() |
| 134 | if err != nil { |
| 135 | t.Fatal(err) |
| 136 | } else if got != int64(len(expected)) { |
| 137 | t.Fatalf("expected %v, got %v", len(expected), got) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | func TestFstatRemotePartialContent(t *testing.T) { |
| 142 | m := map[string][]string{} |
nothing calls this directly
no test coverage detected