MCPcopy Create free account
hub / github.com/tus/tusd / TestPatch

Function TestPatch

pkg/handler/patch_test.go:19–996  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestPatch(t *testing.T) {
20 SubTest(t, "UploadChunk", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
21 ctrl := gomock.NewController(t)
22 defer ctrl.Finish()
23 upload := NewMockFullUpload(ctrl)
24
25 gomock.InOrder(
26 store.EXPECT().GetUpload(gomock.Any(), "yes").Return(upload, nil),
27 upload.EXPECT().GetInfo(gomock.Any()).Return(FileInfo{
28 ID: "yes",
29 Offset: 5,
30 Size: 10,
31 }, nil),
32 upload.EXPECT().WriteChunk(gomock.Any(), int64(5), NewReaderMatcher("hello")).Return(int64(5), nil),
33 upload.EXPECT().FinishUpload(gomock.Any()),
34 )
35
36 handler, _ := NewHandler(Config{
37 StoreComposer: composer,
38 NotifyCompleteUploads: true,
39 })
40
41 c := make(chan HookEvent, 1)
42 handler.CompleteUploads = c
43
44 (&httpTest{
45 Method: "PATCH",
46 URL: "yes",
47 ReqHeader: map[string]string{
48 "Tus-Resumable": "1.0.0",
49 "Content-Type": "application/offset+octet-stream",
50 "Upload-Offset": "5",
51 },
52 ReqBody: strings.NewReader("hello"),
53 Code: http.StatusNoContent,
54 ResHeader: map[string]string{
55 "Upload-Offset": "10",
56 },
57 }).Run(handler, t)
58
59 a := assert.New(t)
60 event := <-c
61 info := event.Upload
62 a.Equal("yes", info.ID)
63 a.EqualValues(int64(10), info.Size)
64 a.Equal(int64(10), info.Offset)
65
66 req := event.HTTPRequest
67 a.Equal("PATCH", req.Method)
68 a.Equal("yes", req.URI)
69 a.Equal("5", req.Header.Get("Upload-Offset"))
70 })
71
72 SubTest(t, "MethodOverriding", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
73 ctrl := gomock.NewController(t)
74 defer ctrl.Finish()
75 upload := NewMockFullUpload(ctrl)
76

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
EXPECTMethod · 0.95
EXPECTMethod · 0.95
UseCoreMethod · 0.95
UseLockerMethod · 0.95
SubTestFunction · 0.85
NewMockFullUploadFunction · 0.85
NewReaderMatcherFunction · 0.85
NewHandlerFunction · 0.85
NewMockFullLockerFunction · 0.85
NewMockFullLockFunction · 0.85
NewStoreComposerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…