MCPcopy Create free account
hub / github.com/chanify/chanify / TestFileFailed

Function TestFileFailed

core/file_test.go:167–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

165}
166
167func TestFileFailed(t *testing.T) {
168 logic.APIEndpoint = "http://127.0.0.1"
169 c := New()
170 defer c.Close()
171 c.Init(&logic.Options{DBUrl: "sqlite://?mode=memory"}) // nolint: errcheck
172 w := httptest.NewRecorder()
173 ctx, _ := gin.CreateTestContext(w)
174 ctx.Request, _ = http.NewRequest("GET", "/files/files/1234567890", nil)
175 c.handleFileDownload(ctx)
176 if w.Result().StatusCode != http.StatusUnauthorized {
177 t.Fatal("Check download token failed")
178 }
179
180 tk, _ := model.ParseToken("CNjo6ua-WhIiQUJPTzZUU0lYS1NFVklKS1hMRFFTVVhRUlhVQU9YR0dZWQ..c2lnbg") // nolint: errcheck
181 w = httptest.NewRecorder()
182 ctx, _ = gin.CreateTestContext(w)
183 ctx.Request, _ = http.NewRequest("GET", "/files/files/1234567890", nil)
184 c.downloadFile(ctx, tk)
185 if w.Result().StatusCode != http.StatusUnauthorized {
186 t.Fatal("Check download url hash failed")
187 }
188
189 tk, _ = model.ParseToken("EgMxMjMiBGNoYW4qBU1GUkdHMhQZZ_-_F4Oa-oQO0sLHXKqNSU8Qmw..c2lnbg") // nolint: errcheck
190 w = httptest.NewRecorder()
191 ctx, _ = gin.CreateTestContext(w)
192 ctx.Request, _ = http.NewRequest("GET", "/files/files/1234567890", nil)
193 ctx.Request.URL.Path = "/files/files/1234567890"
194 c.downloadFile(ctx, tk)
195 if w.Result().StatusCode != http.StatusBadRequest {
196 t.Fatal("Check download file url hash failed", w.Result().StatusCode)
197 }
198
199 w = httptest.NewRecorder()
200 ctx, _ = gin.CreateTestContext(w)
201 ctx.Request, _ = http.NewRequest("GET", "/files/files/1234567890", nil)
202 ctx.Request.URL.Path = "/files/files/1234567890"
203 ctx.Params = []gin.Param{{Key: "fname", Value: "1234567890"}}
204 c.downloadFile(ctx, tk)
205 if w.Result().StatusCode != http.StatusNotFound {
206 t.Fatal("Check download file name failed")
207 }
208}

Callers

nothing calls this directly

Calls 6

ParseTokenFunction · 0.92
NewFunction · 0.85
InitMethod · 0.80
handleFileDownloadMethod · 0.80
downloadFileMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected