File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -292,12 +292,16 @@ impl Default for Breadcrumb {
292
292
#[ serde( default ) ]
293
293
pub struct User {
294
294
/// The ID of the user.
295
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
295
296
pub id : Option < String > ,
296
297
/// The email address of the user.
298
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
297
299
pub email : Option < String > ,
298
300
/// The remote ip address of the user.
301
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
299
302
pub ip_address : Option < IpAddr > ,
300
303
/// A human readable username of the user.
304
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
301
305
pub username : Option < String > ,
302
306
/// Additional data that should be send along.
303
307
#[ serde( flatten) ]
Original file line number Diff line number Diff line change @@ -182,6 +182,47 @@ fn test_repos() {
182
182
) ;
183
183
}
184
184
185
+ #[ test]
186
+ fn test_user ( ) {
187
+ let event = v7:: Event {
188
+ user : Some ( v7:: User {
189
+ id : Some ( "8fd5a33b-5b0e-45b2-aff2-9e4f067756ba" . into ( ) ) ,
190
+ email : Some ( "[email protected] " . into ( ) ) ,
191
+ ip_address : Some ( "127.0.0.1" . parse ( ) . unwrap ( ) ) ,
192
+ username : Some ( "john-doe" . into ( ) ) ,
193
+ data : {
194
+ let mut hm = HashMap :: new ( ) ;
195
+ hm. insert ( "foo" . into ( ) , "bar" . into ( ) ) ;
196
+ hm
197
+ }
198
+ } ) ,
199
+ ..Default :: default ( )
200
+ } ;
201
+
202
+ assert_eq ! (
203
+ serde_json:: to_string( & event) . unwrap( ) ,
204
+ "{\" user\" :{\" id\" :\" 8fd5a33b-5b0e-45b2-aff2-9e4f067756ba\" ,\
205
+ \" email\" :\" [email protected] \" ,\" ip_address\" :\" 127.0.0.1\" ,\
206
+ \" username\" :\" john-doe\" ,\" foo\" :\" bar\" }}"
207
+ ) ;
208
+
209
+ let event = v7:: Event {
210
+ user : Some ( v7:: User {
211
+ id : Some ( "8fd5a33b-5b0e-45b2-aff2-9e4f067756ba" . into ( ) ) ,
212
+ email : None ,
213
+ ip_address : None ,
214
+ username : None ,
215
+ ..Default :: default ( )
216
+ } ) ,
217
+ ..Default :: default ( )
218
+ } ;
219
+
220
+ assert_eq ! (
221
+ serde_json:: to_string( & event) . unwrap( ) ,
222
+ "{\" user\" :{\" id\" :\" 8fd5a33b-5b0e-45b2-aff2-9e4f067756ba\" }}"
223
+ ) ;
224
+ }
225
+
185
226
#[ test]
186
227
fn test_canonical_exception ( ) {
187
228
let mut event: v7:: Event = Default :: default ( ) ;
You can’t perform that action at this time.
0 commit comments