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

Function TestDocAttachmentMetaOption

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

Source from the content-addressed store, hash-verified

139}
140
141func TestDocAttachmentMetaOption(t *testing.T) {
142 rt := NewRestTester(t, &RestTesterConfig{GuestEnabled: true})
143 defer rt.Close()
144
145 version := rt.PutDoc("doc", `{"prop":true}`)
146
147 attachmentBody := "this is the body of attachment"
148 attachmentContentType := "content/type"
149
150 // Validate attachment response.
151 assertAttachmentResponse := func(response *TestResponse) {
152 RequireStatus(t, response, http.StatusOK)
153 assert.Equal(t, attachmentBody, response.Body.String())
154 assert.Equal(t, "bytes", response.Header().Get("Accept-Ranges"))
155 assert.Empty(t, response.Header().Get("Content-Disposition"))
156 assert.Equal(t, "30", response.Header().Get("Content-Length"))
157 assert.Equal(t, attachmentContentType, response.Header().Get("Content-Type"))
158 }
159
160 // Attach to existing document.
161 _ = rt.storeAttachment("doc", version, "attach1", attachmentBody)
162
163 // Retrieve attachment
164 response := rt.SendRequest(http.MethodGet, "/{{.keyspace}}/doc/attach1", "")
165 assertAttachmentResponse(response)
166
167 // Retrieve attachment meta only by explicitly enabling meta option.
168 response = rt.SendRequest(http.MethodGet, "/{{.keyspace}}/doc/attach1?meta=true", "")
169 RequireStatus(t, response, http.StatusOK)
170
171 attachment := getAttachmentMetaFromREST(t, response.BodyBytes())
172 require.Equal(t, attachmentMetaResponse{
173 Key: "_sync:att2:E51US4IbE+vqFPGw/hhXciLkFcKWbjo1EcQZYFUjIgI=:sha1-nq0xWBV2IEkkpY3ng+PEtFnCcVY=",
174 DocAttachment: db.DocAttachment{
175 ContentType: attachmentContentType,
176 Digest: "sha1-nq0xWBV2IEkkpY3ng+PEtFnCcVY=",
177 Length: 30,
178 Revpos: 2,
179 Version: 2,
180 Stub: true,
181 },
182 }, attachment)
183
184 // Retrieve attachment by explicitly disabling meta option.
185 response = rt.SendRequest(http.MethodGet, "/{{.keyspace}}/doc/attach1?meta=false", "")
186 assertAttachmentResponse(response)
187 require.Equal(t, attachmentBody, response.BodyString())
188}
189
190// Add an attachment to a document that has been removed from the users channels
191func TestDocAttachmentOnRemovedRev(t *testing.T) {

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
PutDocMethod · 0.95
storeAttachmentMethod · 0.95
SendRequestMethod · 0.95
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
HeaderMethod · 0.80
BodyStringMethod · 0.80
StringMethod · 0.65
EqualMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected