9
9
package adminapitest
10
10
11
11
import (
12
+ "encoding/base64"
12
13
"encoding/json"
13
14
"errors"
14
15
"fmt"
@@ -1794,12 +1795,17 @@ func TestPurgeWithOldAttachment(t *testing.T) {
1794
1795
rt := rest .NewRestTester (t , nil )
1795
1796
defer rt .Close ()
1796
1797
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 )
1798
1801
1799
1802
rawBody , rawXattrs , _ , err := rt .GetSingleDataStore ().GetWithXattrs (t .Context (), "doc1" , []string {base .SyncXattrName , base .GlobalXattrName })
1800
1803
require .NoError (t , err )
1801
1804
assert .NotNil (t , rawBody )
1802
1805
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 )))
1803
1809
1804
1810
response := rt .SendAdminRequest ("POST" , "/{{.keyspace}}/_purge" , `{"doc1":["*"]}` )
1805
1811
rest .RequireStatus (t , response , http .StatusOK )
@@ -1814,13 +1820,20 @@ func TestPurgeWithOldAttachment(t *testing.T) {
1814
1820
assert .Nil (t , rawBody )
1815
1821
assert .Empty (t , rawXattrs )
1816
1822
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 )
1819
1828
1820
1829
rawBody , rawXattrs , _ , err = rt .GetSingleDataStore ().GetWithXattrs (t .Context (), "doc1" , []string {base .SyncXattrName , base .GlobalXattrName })
1821
1830
require .NoError (t , err )
1822
1831
assert .NotNil (t , rawBody )
1823
1832
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 )))
1824
1837
}
1825
1838
1826
1839
// TestRawRedaction tests the /_raw endpoint with and without redaction
0 commit comments