MCPcopy Create free account
hub / github.com/gogs/gogs / TestBasicHandler_serveDownload

Function TestBasicHandler_serveDownload

internal/route/lfs/basic_test.go:40–135  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestBasicHandler_serveDownload(t *testing.T) {
41 s := &mockStorage{}
42 basic := &basicHandler{
43 defaultStorage: s.Storage(),
44 storagers: map[lfsutil.Storage]lfsutil.Storager{
45 s.Storage(): s,
46 },
47 }
48
49 m := macaron.New()
50 m.Use(macaron.Renderer())
51 m.Use(func(c *macaron.Context) {
52 c.Map(&database.Repository{Name: "repo"})
53 c.Map(lfsutil.OID("ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f"))
54 })
55 m.Get("/", basic.serveDownload)
56
57 tests := []struct {
58 name string
59 content string
60 mockStore func() *MockStore
61 expStatusCode int
62 expHeader http.Header
63 expBody string
64 }{
65 {
66 name: "object does not exist",
67 mockStore: func() *MockStore {
68 mockStore := NewMockStore()
69 mockStore.GetLFSObjectByOIDFunc.SetDefaultReturn(nil, database.ErrLFSObjectNotExist{})
70 return mockStore
71 },
72 expStatusCode: http.StatusNotFound,
73 expHeader: http.Header{
74 "Content-Type": []string{"application/vnd.git-lfs+json"},
75 },
76 expBody: `{"message":"Object does not exist"}` + "\n",
77 },
78 {
79 name: "storage not found",
80 mockStore: func() *MockStore {
81 mockStore := NewMockStore()
82 mockStore.GetLFSObjectByOIDFunc.SetDefaultReturn(&database.LFSObject{Storage: "bad_storage"}, nil)
83 return mockStore
84 },
85 expStatusCode: http.StatusInternalServerError,
86 expHeader: http.Header{
87 "Content-Type": []string{"application/vnd.git-lfs+json"},
88 },
89 expBody: `{"message":"Internal server error"}` + "\n",
90 },
91
92 {
93 name: "object exists",
94 content: "Hello world!",
95 mockStore: func() *MockStore {
96 mockStore := NewMockStore()
97 mockStore.GetLFSObjectByOIDFunc.SetDefaultReturn(

Callers

nothing calls this directly

Calls 6

StorageMethod · 0.95
OIDTypeAlias · 0.92
NewMockStoreFunction · 0.85
stringFunction · 0.85
GetMethod · 0.65
SetDefaultReturnMethod · 0.45

Tested by

no test coverage detected