Skip to content

Commit 54b2a3a

Browse files
committed
fix(rotate): add missing argocd sync content type
fix test by... - awaiting argocd rollout before start - using multi-threaded runtime - because port-forward was blocked otherwise - removing timeout on multi-threaded tests
1 parent 7f75665 commit 54b2a3a

File tree

5 files changed

+214
-194
lines changed

5 files changed

+214
-194
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ serde = { version = "1.0.210", features = ["derive"] }
1414
reqwest = { version = "0.12.7", features = ["json"] }
1515
serde_json = "1.0.128"
1616
serde_yaml = "0.9.34+deprecated"
17-
tokio = { version = "1.40.0", features = ["macros", "rt"] }
17+
tokio = { version = "1.40.0", features = ["rt"] }
1818
urlencoding = "2.1.3"
1919
vaultrs = "0.7.2"
2020

@@ -24,5 +24,6 @@ ntest = "0.9.3"
2424
predicates = "3.1.2"
2525
schemars = "0.8.21"
2626
testcontainers-modules = { version = "0.10.0", features = ["hashicorp_vault", "k3s", "postgres"] }
27+
tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] }
2728
tokio-postgres = "0.7.11"
2829
utilities = {path= "tests/utilities" }

src/argo_cd.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use log::{debug, info, warn};
2+
use reqwest::header::CONTENT_TYPE;
23
use reqwest::{Client, RequestBuilder};
34
use serde::Deserialize;
4-
use serde_json::json;
55
use std::env;
66
use std::thread::sleep;
77
use std::time::{Duration, Instant};
@@ -45,11 +45,10 @@ impl ArgoCD {
4545
name = encode(app_name)
4646
);
4747

48-
let sync_parameters = json!({
49-
"name": app_name,
50-
});
51-
52-
let request_builder = self.client.post(url.as_str()).json(&sync_parameters);
48+
let request_builder = self
49+
.client
50+
.post(url.as_str())
51+
.header(CONTENT_TYPE, "application/json");
5352
let request_builder = Self::enhance_with_authorization_token_if_applicable(request_builder);
5453

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

75+
debug!("ArgoCD sync triggered, waiting for status update");
76+
7677
fn is_status_in_progress(app_information: &Application) -> bool {
7778
app_information
7879
.status
@@ -170,7 +171,7 @@ impl ArgoCD {
170171
self.client.execute(
171172
request
172173
.try_clone()
173-
.expect("Failed to request ArgoCD sync status"),
174+
.expect("Failed to build ArgoCD sync status request"),
174175
),
175176
)
176177
.expect("Failed to request ArgoCD sync status");

tests/init_vault.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::process::{Command, Stdio};
33
use assert_cmd::prelude::*;
44
use ntest::timeout;
55
use predicates::str::contains;
6-
use serde_json::Value;
76
use utilities::{
8-
create_vault_client, read_secret_as_json, vault_container, write_string_to_tempfile,
7+
create_vault_client, read_vault_secret, vault_container, write_string_to_tempfile,
98
};
109

1110
#[tokio::test]
@@ -50,14 +49,14 @@ vault:
5049
));
5150

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

55-
assert_json_value_equals(&json_secret, "postgresql_active_user", "TBD");
56-
assert_json_value_equals(&json_secret, "postgresql_active_user_password", "TBD");
57-
assert_json_value_equals(&json_secret, "postgresql_user_1", "TBD");
58-
assert_json_value_equals(&json_secret, "postgresql_user_1_password", "TBD");
59-
assert_json_value_equals(&json_secret, "postgresql_user_2", "TBD");
60-
assert_json_value_equals(&json_secret, "postgresql_user_2_password", "TBD");
54+
assert_eq!(vault_secret.postgresql_active_user, "TBD");
55+
assert_eq!(vault_secret.postgresql_active_user_password, "TBD");
56+
assert_eq!(vault_secret.postgresql_user_1, "TBD");
57+
assert_eq!(vault_secret.postgresql_user_1_password, "TBD");
58+
assert_eq!(vault_secret.postgresql_user_2, "TBD");
59+
assert_eq!(vault_secret.postgresql_user_2_password, "TBD");
6160
}
6261

6362
#[tokio::test]
@@ -80,12 +79,3 @@ async fn init_vault_invalid_url() {
8079
.stderr(contains("Failed to create initial Vault structure"))
8180
.stderr(contains("error sending request for url"));
8281
}
83-
84-
fn assert_json_value_equals(json: &Value, key: &str, value: &str) {
85-
assert_eq!(
86-
json[key]
87-
.as_str()
88-
.expect(format!("Failed to read key '{}' in JSON", key).as_str()),
89-
value
90-
);
91-
}

0 commit comments

Comments
 (0)