Skip to content

Commit daa42e4

Browse files
committed
Add test coverage for the revived attachment case anyay just to catch any potential future regressions
1 parent 2369b91 commit daa42e4

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

rest/adminapitest/admin_api_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package adminapitest
1010

1111
import (
12+
"encoding/base64"
1213
"encoding/json"
1314
"errors"
1415
"fmt"
@@ -1794,12 +1795,17 @@ func TestPurgeWithOldAttachment(t *testing.T) {
17941795
rt := rest.NewRestTester(t, nil)
17951796
defer rt.Close()
17961797

1797-
_ = rt.PutDocWithAttachment("doc1", `{"foo":"doc1"}`, "att1", "b25lCg==")
1798+
const att1 = "first attachment"
1799+
att1Data := base64.StdEncoding.EncodeToString([]byte(att1))
1800+
_ = rt.PutDocWithAttachment("doc1", `{"foo":"doc1"}`, "att1", att1Data)
17981801

17991802
rawBody, rawXattrs, _, err := rt.GetSingleDataStore().GetWithXattrs(t.Context(), "doc1", []string{base.SyncXattrName, base.GlobalXattrName})
18001803
require.NoError(t, err)
18011804
assert.NotNil(t, rawBody)
18021805
assert.NotNil(t, rawXattrs)
1806+
var gloablSync db.GlobalSyncData
1807+
require.NoError(t, json.Unmarshal(rawXattrs[base.GlobalXattrName], &gloablSync))
1808+
assert.Equal(t, len(att1), int(gloablSync.Attachments["att1"].(map[string]any)["length"].(float64)))
18031809

18041810
response := rt.SendAdminRequest("POST", "/{{.keyspace}}/_purge", `{"doc1":["*"]}`)
18051811
rest.RequireStatus(t, response, http.StatusOK)
@@ -1814,13 +1820,20 @@ func TestPurgeWithOldAttachment(t *testing.T) {
18141820
assert.Nil(t, rawBody)
18151821
assert.Empty(t, rawXattrs)
18161822

1817-
// Here we're overwriting any previous global sync that may exist, so attachments being resurrected aren't an actual issue for us.
1818-
_ = rt.PutDocDirectly("doc1", db.Body{"foo": "doc1"})
1823+
// Overwriting the document here is intentional: after purging, we want to verify that re-inserting the document does not resurrect any previous attachments or metadata.
1824+
// This ensures the purge operation fully removed all traces of the original document, and that the new insert starts from a clean state.
1825+
const att2 = "att two"
1826+
att2Data := base64.StdEncoding.EncodeToString([]byte(att2))
1827+
_ = rt.PutDocWithAttachment("doc1", `{"foo":"doc1"}`, "att2", att2Data)
18191828

18201829
rawBody, rawXattrs, _, err = rt.GetSingleDataStore().GetWithXattrs(t.Context(), "doc1", []string{base.SyncXattrName, base.GlobalXattrName})
18211830
require.NoError(t, err)
18221831
assert.NotNil(t, rawBody)
18231832
assert.NotNil(t, rawXattrs)
1833+
gloablSync = db.GlobalSyncData{}
1834+
require.NoError(t, json.Unmarshal(rawXattrs[base.GlobalXattrName], &gloablSync))
1835+
assert.NotContains(t, gloablSync.Attachments, "att1")
1836+
assert.Equal(t, len(att2), int(gloablSync.Attachments["att2"].(map[string]any)["length"].(float64)))
18241837
}
18251838

18261839
// TestRawRedaction tests the /_raw endpoint with and without redaction

0 commit comments

Comments
 (0)