@@ -3785,6 +3785,110 @@ func TestOpsCrudCounterNonNumericDoc(t *testing.T) {
37853785 require .ErrorIs (t , err , memdx .ErrDeltaBadval )
37863786}
37873787
3788+ func TestOpsCrudGetEx (t * testing.T ) {
3789+ testutilsint .SkipIfShortTest (t )
3790+ testutilsint .SkipIfOlderServerVersion (t , "8.0.0" )
3791+
3792+ t .Run ("Basic" , func (t * testing.T ) {
3793+ key := []byte (uuid .NewString ())
3794+
3795+ cli := createTestClient (t )
3796+
3797+ _ , err := memdx .SyncUnaryCall (memdx.OpsCrud {
3798+ CollectionsEnabled : true ,
3799+ ExtFramesEnabled : true ,
3800+ }, memdx .OpsCrud .Set , cli , & memdx.SetRequest {
3801+ CollectionID : 0 ,
3802+ Key : key ,
3803+ VbucketID : defaultTestVbucketID ,
3804+ Value : []byte (`{"key":"value"}` ),
3805+ })
3806+ require .NoError (t , err )
3807+
3808+ resp , err := memdx .SyncUnaryCall (memdx.OpsCrud {
3809+ CollectionsEnabled : true ,
3810+ ExtFramesEnabled : true ,
3811+ }, memdx .OpsCrud .GetEx , cli , & memdx.GetExRequest {
3812+ CollectionID : 0 ,
3813+ Key : key ,
3814+ VbucketID : defaultTestVbucketID ,
3815+ })
3816+ require .NoError (t , err )
3817+
3818+ hasXattrs := resp .Datatype & uint8 (memdx .DatatypeFlagXattrs ) != 0
3819+ require .False (t , hasXattrs )
3820+
3821+ require .NoError (t , err )
3822+ require .Equal (t , []byte (`{"key":"value"}` ), resp .Value )
3823+ })
3824+
3825+ t .Run ("WithXattrs" , func (t * testing.T ) {
3826+ key := []byte (uuid .NewString ())
3827+
3828+ cli := createTestClient (t )
3829+
3830+ _ , err := memdx .SyncUnaryCall (memdx.OpsCrud {
3831+ CollectionsEnabled : true ,
3832+ ExtFramesEnabled : true ,
3833+ }, memdx .OpsCrud .Set , cli , & memdx.SetRequest {
3834+ CollectionID : 0 ,
3835+ Key : key ,
3836+ VbucketID : defaultTestVbucketID ,
3837+ Value : []byte (`{"key":"value"}` ),
3838+ })
3839+ require .NoError (t , err )
3840+
3841+ _ , err = memdx .SyncUnaryCall (memdx.OpsCrud {
3842+ CollectionsEnabled : true ,
3843+ ExtFramesEnabled : true ,
3844+ }, memdx .OpsCrud .MutateIn , cli , & memdx.MutateInRequest {
3845+ CollectionID : 0 ,
3846+ Key : key ,
3847+ VbucketID : defaultTestVbucketID ,
3848+ Ops : []memdx.MutateInOp {
3849+ {
3850+ Op : memdx .MutateInOpTypeDictSet ,
3851+ Path : []byte ("_foo" ),
3852+ Value : []byte (`{"x":"y"}` ),
3853+ Flags : memdx .SubdocOpFlagXattrPath ,
3854+ },
3855+ {
3856+ Op : memdx .MutateInOpTypeDictSet ,
3857+ Path : []byte ("_bar" ),
3858+ Value : []byte (`{"y":"z"}` ),
3859+ Flags : memdx .SubdocOpFlagXattrPath ,
3860+ },
3861+ },
3862+ })
3863+ require .NoError (t , err )
3864+
3865+ resp , err := memdx .SyncUnaryCall (memdx.OpsCrud {
3866+ CollectionsEnabled : true ,
3867+ ExtFramesEnabled : true ,
3868+ }, memdx .OpsCrud .GetEx , cli , & memdx.GetExRequest {
3869+ CollectionID : 0 ,
3870+ Key : key ,
3871+ VbucketID : defaultTestVbucketID ,
3872+ })
3873+ require .NoError (t , err )
3874+
3875+ hasXattrs := resp .Datatype & uint8 (memdx .DatatypeFlagXattrs ) != 0
3876+ require .True (t , hasXattrs )
3877+
3878+ xattrBlob , docValue , err := memdx .SplitXattrBlob (resp .Value )
3879+ require .NoError (t , err )
3880+
3881+ xattrs := make (map [string ]string )
3882+ err = memdx .IterXattrBlobEntries (xattrBlob , func (name , value string ) {
3883+ xattrs [name ] = value
3884+ })
3885+ require .NoError (t , err )
3886+ require .Equal (t , map [string ]string {"_foo" : `{"x":"y"}` , "_bar" : `{"y":"z"}` }, xattrs )
3887+
3888+ require .Equal (t , []byte (`{"key":"value"}` ), docValue )
3889+ })
3890+ }
3891+
37883892type testCrudDispatcher struct {
37893893 Pak * memdx.Packet
37903894}
0 commit comments