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

Function TestWriteJSONPart

rest/multipart_test.go:161–179  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

159}
160
161func TestWriteJSONPart(t *testing.T) {
162 // writeJSONPart toggles compression to false if the incoming body is less than 300 bytes, so creating
163 // a body larger than 300 bytes to test writeJSONPart with compression=true and compression=false
164 mockFakeBody := func() db.Body {
165 bytes := base.FastRandBytes(t, 139)
166 value := fmt.Sprintf("%x", bytes)
167 return db.Body{"key": "foo", "value": value}
168 }
169
170 body := mockFakeBody()
171 log.Printf("body: %v", body)
172 buffer := &bytes.Buffer{}
173 writer := multipart.NewWriter(buffer)
174 bytes, err := base.JSONMarshalCanonical(body)
175 require.NoError(t, err)
176 log.Printf("len(bytes): %v", len(bytes))
177 assert.NoError(t, writeJSONPart(writer, "application/json", body, true))
178 assert.NoError(t, writeJSONPart(writer, "application/json", body, false))
179}
180
181func TestMd5DigestKey(t *testing.T) {
182 assert.Equal(t, "md5-rL0Y20zC+Fzt72VPzMSk2A==", md5DigestKey([]byte("foo")))

Callers

nothing calls this directly

Calls 3

FastRandBytesFunction · 0.92
JSONMarshalCanonicalFunction · 0.92
writeJSONPartFunction · 0.85

Tested by

no test coverage detected