@@ -235,11 +235,24 @@ func Test_beforeUpdate(t *testing.T) {
235235 want : nil ,
236236 },
237237 {
238- name : "a bson.M updates without $set" ,
238+ name : "a bson.M updates without $set and not additional fields " ,
239239 updates : bson.M {},
240240 fields : []* field.Filed {},
241241 want : bson.M {},
242242 },
243+ {
244+ name : "a bson.M updates without $set" ,
245+ updates : bson.M {},
246+ currentTime : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
247+ fields : field .ParseFields (& user {}),
248+ want : bson.M {"$set" : bson.M {"updated_at" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ), "update_second_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).Unix (), "update_milli_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (), "update_nano_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixNano ()}},
249+ },
250+ {
251+ name : "a bson.M updates with invalid $set" ,
252+ updates : bson.M {"$set" : "invalid" },
253+ fields : field .ParseFields (& user {}),
254+ want : bson.M {"$set" : "invalid" },
255+ },
243256 {
244257 name : "a bson.M updates but not additional fields" ,
245258 updates : bson.M {"$set" : bson.M {"name" : "Mingyong Chen" }},
@@ -317,11 +330,24 @@ func Test_beforeUpsert(t *testing.T) {
317330 want : nil ,
318331 },
319332 {
320- name : "a bson.M updates without $set" ,
333+ name : "a bson.M updates without $set and not additional fields " ,
321334 updates : bson.M {},
322335 fields : []* field.Filed {},
323336 want : bson.M {},
324337 },
338+ {
339+ name : "a bson.M updates without $set" ,
340+ updates : bson.M {},
341+ currentTime : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
342+ fields : field .ParseFields (& updatedUser {}),
343+ want : bson.M {"$set" : bson.M {"updated_at" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ), "update_second_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).Unix (), "update_milli_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (), "update_nano_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixNano ()}, "$setOnInsert" : bson.M {"created_at" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ), "create_second_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).Unix (), "create_milli_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (), "create_nano_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixNano ()}},
344+ },
345+ {
346+ name : "a bson.M updates with invalid $set" ,
347+ updates : bson.M {"$set" : "invalid" },
348+ fields : []* field.Filed {},
349+ want : bson.M {"$set" : "invalid" },
350+ },
325351 {
326352 name : "a bson.M updates but not additional fields" ,
327353 updates : bson.M {"$set" : bson.M {"name" : "Mingyong Chen" }},
@@ -335,13 +361,6 @@ func Test_beforeUpsert(t *testing.T) {
335361 fields : field .ParseFields (& user {}),
336362 want : bson.M {"$set" : bson.M {"name" : "Mingyong Chen" , "updated_at" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ), "update_second_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).Unix (), "update_milli_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (), "update_nano_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixNano ()}, "$setOnInsert" : "invalid" },
337363 },
338- {
339- name : "a bson.M updates with invalid $setOnInsert" ,
340- updates : bson.M {"$set" : bson.M {"name" : "Mingyong Chen" }, "$setOnInsert" : "invalid" },
341- currentTime : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
342- fields : field .ParseFields (& user2 {}),
343- want : bson.M {"$set" : bson.M {"name" : "Mingyong Chen" , "updated_at" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (), "update_second_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).Unix (), "update_milli_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (), "update_nano_time" : time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixNano ()}, "$setOnInsert" : "invalid" },
344- },
345364 {
346365 name : "a bson.M updates" ,
347366 updates : bson.M {"$set" : bson.M {"name" : "Mingyong Chen" }},
0 commit comments