(t *testing.T)
| 4033 | } |
| 4034 | |
| 4035 | func Test_resyncDocument(t *testing.T) { |
| 4036 | db, ctx := setupTestDB(t) |
| 4037 | defer db.Close(ctx) |
| 4038 | |
| 4039 | db.Options.EnableXattr = true |
| 4040 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 4041 | |
| 4042 | testCases := []struct { |
| 4043 | name string |
| 4044 | useHLV bool |
| 4045 | }{ |
| 4046 | { |
| 4047 | name: "pre 4.0", |
| 4048 | useHLV: false, |
| 4049 | }, |
| 4050 | { |
| 4051 | name: "has hlv", |
| 4052 | useHLV: true, |
| 4053 | }, |
| 4054 | } |
| 4055 | |
| 4056 | for _, tc := range testCases { |
| 4057 | t.Run(tc.name, func(t *testing.T) { |
| 4058 | startingSyncFnCount := int(db.DbStats.Database().SyncFunctionCount.Value()) |
| 4059 | syncFn := ` |
| 4060 | function sync(doc, oldDoc){ |
| 4061 | channel("channel." + "ABC"); |
| 4062 | } |
| 4063 | ` |
| 4064 | _, err := collection.UpdateSyncFun(ctx, syncFn) |
| 4065 | require.NoError(t, err) |
| 4066 | |
| 4067 | docID := uuid.NewString() |
| 4068 | |
| 4069 | updateBody := make(map[string]any) |
| 4070 | updateBody["val"] = "value" |
| 4071 | if tc.useHLV { |
| 4072 | _, _, err := collection.Put(ctx, docID, updateBody) |
| 4073 | require.NoError(t, err) |
| 4074 | } else { |
| 4075 | collection.CreateDocNoHLV(t, ctx, docID, updateBody) |
| 4076 | } |
| 4077 | |
| 4078 | syncFn = ` |
| 4079 | function sync(doc, oldDoc){ |
| 4080 | channel("channel." + "ABC12332423234"); |
| 4081 | } |
| 4082 | ` |
| 4083 | _, err = collection.UpdateSyncFun(ctx, syncFn) |
| 4084 | require.NoError(t, err) |
| 4085 | |
| 4086 | preResyncDoc, err := collection.GetDocument(ctx, docID, DocUnmarshalAll) |
| 4087 | require.NoError(t, err) |
| 4088 | if !tc.useHLV { |
| 4089 | require.Nil(t, preResyncDoc.HLV) |
| 4090 | } |
| 4091 | _, _, err = collection.ResyncDocument(ctx, docID, realDocID(docID), false, []uint64{10}) |
| 4092 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected