Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Acollie committed Jun 6, 2023
1 parent 93705ef commit 26433fd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/file_handeling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,34 @@ fn test_file_detection() {
assert_eq!(file_detection("test.js"), FileType::Nodejs);

}
#[test]
fn test_file_detection_fail() {
assert_ne!(file_detection("test.py"), FileType::Go);
assert_ne!(file_detection("test.go"), FileType::Python);
assert_ne!(file_detection("test.js"), FileType::Python);
assert_ne!(file_detection("test.py"), FileType::Nodejs);
assert_ne!(file_detection("test.go"), FileType::Nodejs);
assert_ne!(file_detection("test.js"), FileType::Go);
}
#[test]
fn test_zip_file() {
zip_file("test.py", FileType::Python).expect("Failed to zip file");
zip_file("test.go", FileType::Go).expect("Failed to zip file");
zip_file("test.js", FileType::Nodejs).expect("Failed to zip file");
}

#[test]
fn test_convert_contents_to_blob() {
let blob = convert_contents_to_blob("test.py").expect("Failed to convert contents to blob");
assert_eq!(blob.as_ref(), read("test.py").expect("Failed to read file"));
}

#[test]
#[should_panic]
fn test_file_detection_panic() {
file_detection("test.rs");
}

#[test]
#[should_panic]
fn test_remove_unsupported_file(){
Expand Down
2 changes: 1 addition & 1 deletion src/lambda_handeling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub async fn get_lambda_names(client:&Client)->HashSet<String>{
functions_names.insert(function.function_name().unwrap().to_string());
}
return functions_names
}
}
13 changes: 13 additions & 0 deletions src/upload_handeling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub async fn lambda_upload(lambda_functions:&HashSet<String>,service_role:&str,c


let runtime = resolve_runtime(file_type);
if cfg!(test) {
return Ok(())
}
if lambda_functions.contains(function_name){
client.update_function_code().function_name(function_name)
.zip_file(convert_contents_to_blob("deployment.zip").unwrap()).send()
Expand All @@ -34,4 +37,14 @@ pub async fn lambda_upload(lambda_functions:&HashSet<String>,service_role:&str,c
.await.unwrap();
}
Ok(())
}

#[cfg(test)]
async fn test_lambda_upload(){
let mut lambda_functions = HashSet::new();
lambda_functions.insert("test".to_string());
let config = aws_config::load_from_env().await;
let client = lambda::Client::new(&config);
let result = lambda_upload(&lambda_functions,"test",&client,"test.py",FileType::Python,"test").await;
assert_eq!(result.is_ok(),true);
}

0 comments on commit 26433fd

Please sign in to comment.