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

Function TestImageFileFailed

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

Source from the content-addressed store, hash-verified

35}
36
37func TestImageFileFailed(t *testing.T) {
38 logic.APIEndpoint = "http://127.0.0.1"
39 c := New()
40 defer c.Close()
41 c.Init(&logic.Options{DBUrl: "sqlite://?mode=memory"}) // nolint: errcheck
42 w := httptest.NewRecorder()
43 ctx, _ := gin.CreateTestContext(w)
44 ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil)
45 c.handleImageDownload(ctx)
46 if w.Result().StatusCode != http.StatusUnauthorized {
47 t.Fatal("Check download token failed")
48 }
49
50 tk, _ := model.ParseToken("EiJBQk9PNlRTSVhLU0VWSUpLWExEUVNVWFFSWFVBT1hHR1lZIgRjaGFuKgVNRlJHRzIUx5tXg-Vym58og7aZw05IkoDvse8..c2lnbg") // nolint: errcheck
51 w = httptest.NewRecorder()
52 ctx, _ = gin.CreateTestContext(w)
53 ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil)
54 c.downloadImageFile(ctx, tk)
55 if w.Result().StatusCode != http.StatusUnauthorized {
56 t.Fatal("Check download url hash failed")
57 }
58
59 tk, _ = model.ParseToken("EgMxMjMiBGNoYW4qBU1GUkdHMhTJH7dPQ2HFxdZCWt3RPyCM8SMJeQ..c2lnbg") // nolint: errcheck
60 w = httptest.NewRecorder()
61 ctx, _ = gin.CreateTestContext(w)
62 ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil)
63 ctx.Request.URL.Path = "/files/images/1234567890"
64 c.downloadImageFile(ctx, tk)
65 if w.Result().StatusCode != http.StatusBadRequest {
66 t.Fatal("Check download image url hash failed")
67 }
68
69 w = httptest.NewRecorder()
70 ctx, _ = gin.CreateTestContext(w)
71 ctx.Request, _ = http.NewRequest("GET", "/files/images/1234567890", nil)
72 ctx.Request.URL.Path = "/files/images/1234567890"
73 ctx.Params = []gin.Param{{Key: "fname", Value: "1234567890"}}
74 c.downloadImageFile(ctx, tk)
75 if w.Result().StatusCode != http.StatusNotFound {
76 t.Fatal("Check download image name failed")
77 }
78}
79
80func TestAudioFile(t *testing.T) {
81 fpath := filepath.Join(os.TempDir(), "files")

Callers

nothing calls this directly

Calls 6

ParseTokenFunction · 0.92
NewFunction · 0.85
InitMethod · 0.80
handleImageDownloadMethod · 0.80
downloadImageFileMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected