@@ -91,8 +91,7 @@ impl Resource {
91
91
92
92
/// Create a new `Resource` from key value pairs.
93
93
///
94
- /// Values are de-duplicated by key, and the first key-value pair with a non-empty string value
95
- /// will be retained
94
+ /// Values are de-duplicated by key, and the last key-value pair will be retained
96
95
pub ( crate ) fn new < T : IntoIterator < Item = KeyValue > > ( kvs : T ) -> Self {
97
96
let mut attrs = HashMap :: new ( ) ;
98
97
for kv in kvs {
@@ -331,18 +330,24 @@ mod tests {
331
330
332
331
use super :: * ;
333
332
334
- #[ test]
335
- fn new_resource ( ) {
336
- let args_with_dupe_keys = [ KeyValue :: new ( "a" , "" ) , KeyValue :: new ( "a" , "final" ) ] ;
337
-
338
- let mut expected_attrs = HashMap :: new ( ) ;
339
- expected_attrs. insert ( Key :: new ( "a" ) , Value :: from ( "final" ) ) ;
333
+ #[ rstest]
334
+ #[ case( [ KeyValue :: new( "a" , "" ) , KeyValue :: new( "a" , "final" ) ] , [ ( Key :: new( "a" ) , Value :: from( "final" ) ) ] ) ]
335
+ #[ case( [ KeyValue :: new( "a" , "final" ) , KeyValue :: new( "a" , "" ) ] , [ ( Key :: new( "a" ) , Value :: from( "" ) ) ] ) ]
336
+ fn new_resource (
337
+ #[ case] given_attributes : [ KeyValue ; 2 ] ,
338
+ #[ case] expected_attrs : [ ( Key , Value ) ; 1 ] ,
339
+ ) {
340
+ // Arrange
341
+ let expected = HashMap :: from_iter ( expected_attrs. into_iter ( ) ) ;
340
342
343
+ // Act
341
344
let resource = Resource :: builder_empty ( )
342
- . with_attributes ( args_with_dupe_keys )
345
+ . with_attributes ( given_attributes )
343
346
. build ( ) ;
344
347
let resource_inner = Arc :: try_unwrap ( resource. inner ) . expect ( "Failed to unwrap Arc" ) ;
345
- assert_eq ! ( resource_inner. attrs, expected_attrs) ;
348
+
349
+ // Assert
350
+ assert_eq ! ( resource_inner. attrs, expected) ;
346
351
assert_eq ! ( resource_inner. schema_url, None ) ;
347
352
}
348
353
0 commit comments