Skip to content

Commit

Permalink
fix(rotate): add missing argocd sync content type
Browse files Browse the repository at this point in the history
fix test by...

- awaiting argocd rollout before start
- using multi-threaded runtime
    - because port-forward was blocked otherwise
- removing timeout on multi-threaded tests
  • Loading branch information
bbortt committed Sep 14, 2024
1 parent 7f75665 commit 54b2a3a
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 194 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde = { version = "1.0.210", features = ["derive"] }
reqwest = { version = "0.12.7", features = ["json"] }
serde_json = "1.0.128"
serde_yaml = "0.9.34+deprecated"
tokio = { version = "1.40.0", features = ["macros", "rt"] }
tokio = { version = "1.40.0", features = ["rt"] }
urlencoding = "2.1.3"
vaultrs = "0.7.2"

Expand All @@ -24,5 +24,6 @@ ntest = "0.9.3"
predicates = "3.1.2"
schemars = "0.8.21"
testcontainers-modules = { version = "0.10.0", features = ["hashicorp_vault", "k3s", "postgres"] }
tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] }
tokio-postgres = "0.7.11"
utilities = {path= "tests/utilities" }
15 changes: 8 additions & 7 deletions src/argo_cd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use log::{debug, info, warn};
use reqwest::header::CONTENT_TYPE;
use reqwest::{Client, RequestBuilder};
use serde::Deserialize;
use serde_json::json;
use std::env;
use std::thread::sleep;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -45,11 +45,10 @@ impl ArgoCD {
name = encode(app_name)
);

let sync_parameters = json!({
"name": app_name,
});

let request_builder = self.client.post(url.as_str()).json(&sync_parameters);
let request_builder = self
.client
.post(url.as_str())
.header(CONTENT_TYPE, "application/json");
let request_builder = Self::enhance_with_authorization_token_if_applicable(request_builder);

let request = request_builder
Expand All @@ -73,6 +72,8 @@ impl ArgoCD {
panic!("Failed to sync ArgoCD: {}", argocd_response)
}

debug!("ArgoCD sync triggered, waiting for status update");

fn is_status_in_progress(app_information: &Application) -> bool {
app_information
.status
Expand Down Expand Up @@ -170,7 +171,7 @@ impl ArgoCD {
self.client.execute(
request
.try_clone()
.expect("Failed to request ArgoCD sync status"),
.expect("Failed to build ArgoCD sync status request"),
),
)
.expect("Failed to request ArgoCD sync status");
Expand Down
26 changes: 8 additions & 18 deletions tests/init_vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::process::{Command, Stdio};
use assert_cmd::prelude::*;
use ntest::timeout;
use predicates::str::contains;
use serde_json::Value;
use utilities::{
create_vault_client, read_secret_as_json, vault_container, write_string_to_tempfile,
create_vault_client, read_vault_secret, vault_container, write_string_to_tempfile,
};

#[tokio::test]
Expand Down Expand Up @@ -50,14 +49,14 @@ vault:
));

let vault_client = create_vault_client(vault_host.to_string().as_str(), vault_port);
let json_secret = read_secret_as_json(&vault_client, "init/vault/new/path").await;
let vault_secret = read_vault_secret(&vault_client, "init/vault/new/path").await;

assert_json_value_equals(&json_secret, "postgresql_active_user", "TBD");
assert_json_value_equals(&json_secret, "postgresql_active_user_password", "TBD");
assert_json_value_equals(&json_secret, "postgresql_user_1", "TBD");
assert_json_value_equals(&json_secret, "postgresql_user_1_password", "TBD");
assert_json_value_equals(&json_secret, "postgresql_user_2", "TBD");
assert_json_value_equals(&json_secret, "postgresql_user_2_password", "TBD");
assert_eq!(vault_secret.postgresql_active_user, "TBD");
assert_eq!(vault_secret.postgresql_active_user_password, "TBD");
assert_eq!(vault_secret.postgresql_user_1, "TBD");
assert_eq!(vault_secret.postgresql_user_1_password, "TBD");
assert_eq!(vault_secret.postgresql_user_2, "TBD");
assert_eq!(vault_secret.postgresql_user_2_password, "TBD");
}

#[tokio::test]
Expand All @@ -80,12 +79,3 @@ async fn init_vault_invalid_url() {
.stderr(contains("Failed to create initial Vault structure"))
.stderr(contains("error sending request for url"));
}

fn assert_json_value_equals(json: &Value, key: &str, value: &str) {
assert_eq!(
json[key]
.as_str()
.expect(format!("Failed to read key '{}' in JSON", key).as_str()),
value
);
}
Loading

0 comments on commit 54b2a3a

Please sign in to comment.