MCPcopy Create free account
hub / github.com/Azure/peerd / TestFstatRemote

Function TestFstatRemote

pkg/discovery/content/reader/reader_test.go:98–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func 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
141func TestFstatRemotePartialContent(t *testing.T) {
142 m := map[string][]string{}

Callers

nothing calls this directly

Calls 5

NewMockRouterFunction · 0.92
NewReaderFunction · 0.85
SetMethod · 0.80
CloseMethod · 0.65
FstatRemoteMethod · 0.65

Tested by

no test coverage detected