MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestFunkyDocAndAttachmentIDs

Function TestFunkyDocAndAttachmentIDs

rest/attachment_test.go:213–264  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

211}
212
213func TestFunkyDocAndAttachmentIDs(t *testing.T) {
214 rt := NewRestTester(t, &RestTesterConfig{GuestEnabled: true})
215 defer rt.Close()
216
217 attachmentBody := "this is the body of attachment"
218 attachmentContentType := "content/type"
219
220 // assertResponse asserts that the specified attachment exists in the response body.
221 assertResponse := func(response *TestResponse, attachmentBody string) {
222 RequireStatus(t, response, http.StatusOK)
223 require.Equal(t, attachmentBody, response.Body.String())
224 require.Empty(t, response.Header().Get("Content-Disposition"))
225 require.Equal(t, attachmentContentType, response.Header().Get("Content-Type"))
226 }
227 testCases := []struct {
228 name string
229 docID string
230 }{
231 {
232 name: "simple",
233 docID: "doc1",
234 },
235 {
236 name: "single embedded '/'",
237 docID: "AC%2FDC",
238 },
239 {
240 name: "embedded '+'",
241 docID: "AC%2BDC%2BGC2",
242 },
243 }
244 for _, testCase := range testCases {
245 rt.Run(testCase.name, func(t *testing.T) {
246
247 version := rt.CreateTestDoc(testCase.docID)
248
249 // Add attachment with single embedded '/' (%2F HEX)
250 version = rt.storeAttachment(testCase.docID, version, "attachpath%2Fattachment.txt", attachmentBody)
251
252 // Retrieve attachment
253 response := rt.SendRequest(http.MethodGet, "/{{.keyspace}}/doc1/attachpath%2Fattachment.txt", "")
254 assertResponse(response, attachmentBody)
255
256 // Add attachment with two embedded '/' (%2F HEX)
257 _ = rt.storeAttachment(testCase.docID, version, "attachpath%2Fattachpath2%2Fattachment.txt", attachmentBody)
258
259 // Retrieve attachment
260 response = rt.SendRequest(http.MethodGet, "/{{.keyspace}}/doc1/attachpath%2Fattachpath2%2Fattachment.txt", "")
261 assertResponse(response, attachmentBody)
262 })
263 }
264}
265
266func TestManualAttachment(t *testing.T) {
267 rt := NewRestTester(t, &RestTesterConfig{GuestEnabled: true})

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
RunMethod · 0.95
CreateTestDocMethod · 0.95
storeAttachmentMethod · 0.95
SendRequestMethod · 0.95
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
HeaderMethod · 0.80
StringMethod · 0.65
EqualMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected