Skip to content

Commit d3bdf5d

Browse files
committed
Tests for get_function_tags_map.
1 parent bd7987f commit d3bdf5d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

bottlecap/src/tags/lambda/tags.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,43 @@ 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(
406+
function_tags
407+
.get(FUNCTION_TAGS_KEY)
408+
.unwrap()
409+
.split(',')
410+
.map(|tag| {
411+
let parts = tag.split(':').collect::<Vec<&str>>();
412+
(parts[0].to_string(), parts[1].to_string())
413+
}),
414+
);
415+
assert_eq!(fn_tags_map.len(), 14);
416+
assert_eq!(fn_tags_map.get("key1").unwrap(), "value1");
417+
assert_eq!(fn_tags_map.get("key2").unwrap(), "value2");
418+
assert_eq!(fn_tags_map.get(ACCOUNT_ID_KEY).unwrap(), "123456789012");
419+
assert_eq!(fn_tags_map.get(ENV_KEY).unwrap(), "test");
420+
assert_eq!(fn_tags_map.get(FUNCTION_ARN_KEY).unwrap(), "arn");
421+
assert_eq!(fn_tags_map.get(FUNCTION_NAME_KEY).unwrap(), "my-function");
422+
assert_eq!(fn_tags_map.get(REGION_KEY).unwrap(), "us-west-2");
423+
assert_eq!(fn_tags_map.get(SERVICE_KEY).unwrap(), "my-service");
424+
assert_eq!(fn_tags_map.get(VERSION_KEY).unwrap(), "1.0.0");
425+
}
387426
}

0 commit comments

Comments
 (0)