Skip to content

Commit

Permalink
Fix bug where new environment variables were not being added to the s…
Browse files Browse the repository at this point in the history
…ervice.
  • Loading branch information
lazureykis committed Jan 25, 2024
1 parent e9c4c43 commit eb4f1ad
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub fn list_env_pairs_to_update(
if old_env_var_value != &new_env_var_value {
env_vars_to_update.push(format!("{}={}", new_env_var_name, new_env_var_value));
}
} else {
env_vars_to_update.push(format!("{}={}", new_env_var_name, new_env_var_value));
}
}

Expand Down Expand Up @@ -311,6 +313,50 @@ pub async fn match_services(
mod tests {
use super::*;

#[test]
fn test_list_env_pairs_to_update_no_changes() {
let old_env_vars = vec!["VAR1=old_value1".to_string(), "VAR2=old_value2".to_string()];
let new_env_vars = vec!["VAR1=old_value1".to_string(), "VAR2=old_value2".to_string()];

let result = list_env_pairs_to_update(old_env_vars, new_env_vars).unwrap();
assert!(result.is_empty()); // No changes, so the result should be an empty vector
}

#[test]
fn test_list_env_pairs_to_update_with_changes() {
let old_env_vars = vec!["VAR1=old_value1".to_string(), "VAR2=old_value2".to_string()];
let new_env_vars = vec!["VAR1=new_value1".to_string(), "VAR2=old_value2".to_string()];

let result = list_env_pairs_to_update(old_env_vars, new_env_vars).unwrap();
assert_eq!(result, vec!["VAR1=new_value1".to_string()]); // VAR1 has changed, so it should be in the result
}

#[test]
fn test_list_env_pairs_to_update_missing_old_vars() {
let old_env_vars = vec!["VAR1=old_value1".to_string()];
let new_env_vars = vec!["VAR1=new_value1".to_string(), "VAR2=new_value2".to_string()];

let result = list_env_pairs_to_update(old_env_vars, new_env_vars).unwrap();
assert_eq!(
result,
vec!["VAR1=new_value1".to_string(), "VAR2=new_value2".to_string()]
);
// VAR1 has changed, VAR2 is a new variable, both should be in the result
}

#[test]
fn test_list_env_pairs_to_update_new_vars_not_in_old_vars() {
let old_env_vars = vec!["VAR1=old_value1".to_string()];
let new_env_vars = vec!["VAR2=new_value2".to_string(), "VAR3=new_value3".to_string()];

let result = list_env_pairs_to_update(old_env_vars, new_env_vars).unwrap();
assert_eq!(
result,
vec!["VAR2=new_value2".to_string(), "VAR3=new_value3".to_string()]
);
// VAR2 and VAR3 are new variables, both should be in the result
}

#[test]
fn test_is_pattern() {
assert!(is_pattern("pattern_with_asterisk*"));
Expand Down

0 comments on commit eb4f1ad

Please sign in to comment.