@@ -384,4 +384,41 @@ mod tests {
384384 fs:: remove_file ( path) . unwrap ( ) ;
385385 assert_eq ! ( runtime, "provided.al2023" ) ;
386386 }
387+
388+ #[ test]
389+ fn test_get_function_tags_map ( ) {
390+ let mut metadata = hash_map:: HashMap :: new ( ) ;
391+ metadata. insert (
392+ FUNCTION_ARN_KEY . to_string ( ) ,
393+ "arn:aws:lambda:us-west-2:123456789012:function:my-function" . to_string ( ) ,
394+ ) ;
395+ let config = Arc :: new ( Config {
396+ service : Some ( "my-service" . to_string ( ) ) ,
397+ tags : Some ( "key1:value1,key2:value2" . to_string ( ) ) ,
398+ env : Some ( "test" . to_string ( ) ) ,
399+ version : Some ( "1.0.0" . to_string ( ) ) ,
400+ ..Config :: default ( )
401+ } ) ;
402+ let tags = Lambda :: new_from_config ( config, & metadata) ;
403+ let function_tags = tags. get_function_tags_map ( ) ;
404+ assert_eq ! ( function_tags. len( ) , 1 ) ;
405+ let fn_tags_map: hash_map:: HashMap < String , String > = hash_map:: HashMap :: from_iter ( function_tags
406+ . get ( FUNCTION_TAGS_KEY )
407+ . unwrap ( )
408+ . split ( ',' )
409+ . map ( |tag| {
410+ let parts = tag. split ( ':' ) . collect :: < Vec < & str > > ( ) ;
411+ ( parts[ 0 ] . to_string ( ) , parts[ 1 ] . to_string ( ) )
412+ } ) ) ;
413+ assert_eq ! ( fn_tags_map. len( ) , 14 ) ;
414+ assert_eq ! ( fn_tags_map. get( "key1" ) . unwrap( ) , "value1" ) ;
415+ assert_eq ! ( fn_tags_map. get( "key2" ) . unwrap( ) , "value2" ) ;
416+ assert_eq ! ( fn_tags_map. get( ACCOUNT_ID_KEY ) . unwrap( ) , "123456789012" ) ;
417+ assert_eq ! ( fn_tags_map. get( ENV_KEY ) . unwrap( ) , "test" ) ;
418+ assert_eq ! ( fn_tags_map. get( FUNCTION_ARN_KEY ) . unwrap( ) , "arn" ) ;
419+ assert_eq ! ( fn_tags_map. get( FUNCTION_NAME_KEY ) . unwrap( ) , "my-function" ) ;
420+ assert_eq ! ( fn_tags_map. get( REGION_KEY ) . unwrap( ) , "us-west-2" ) ;
421+ assert_eq ! ( fn_tags_map. get( SERVICE_KEY ) . unwrap( ) , "my-service" ) ;
422+ assert_eq ! ( fn_tags_map. get( VERSION_KEY ) . unwrap( ) , "1.0.0" ) ;
423+ }
387424}
0 commit comments