From 1607c407c3f19861dba16c51246e68c195542ea9 Mon Sep 17 00:00:00 2001 From: MasterPtato <23087326+MasterPtato@users.noreply.github.com> Date: Thu, 18 Apr 2024 20:20:32 +0000 Subject: [PATCH] fix: game, ip, and job tests (#566) ## Changes --- .../ops/namespace-get/tests/integration.rs | 7 +++++-- .../ops/version-validate/tests/integration.rs | 2 +- svc/pkg/ip/ops/info/Service.toml | 6 +++--- svc/pkg/ip/ops/info/src/lib.rs | 18 +++++++++++++++--- svc/pkg/job-run/worker/tests/stop.rs | 7 +++---- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/svc/pkg/game/ops/namespace-get/tests/integration.rs b/svc/pkg/game/ops/namespace-get/tests/integration.rs index e4221e5b02..a2ce062015 100644 --- a/svc/pkg/game/ops/namespace-get/tests/integration.rs +++ b/svc/pkg/game/ops/namespace-get/tests/integration.rs @@ -49,10 +49,13 @@ async fn empty(ctx: TestCtx) { }) .await .unwrap(); + let mut res_namespaces = res.namespaces.clone(); + res_namespaces.sort_by(|a, b| a.display_name.cmp(&b.display_name)); test_namespaces.sort_by(|a, b| a.display_name.cmp(&b.display_name)); - assert_eq!(test_namespaces.len(), res.namespaces.len()); - for (a, b) in test_namespaces.iter().zip(res.namespaces.iter()) { + + assert_eq!(test_namespaces.len(), res_namespaces.len()); + for (a, b) in test_namespaces.iter().zip(res_namespaces.iter()) { assert_eq!(a.namespace_id.unwrap(), b.namespace_id.unwrap().as_uuid()); } } diff --git a/svc/pkg/game/ops/version-validate/tests/integration.rs b/svc/pkg/game/ops/version-validate/tests/integration.rs index ee050be4e6..ba7b8da8f0 100644 --- a/svc/pkg/game/ops/version-validate/tests/integration.rs +++ b/svc/pkg/game/ops/version-validate/tests/integration.rs @@ -190,5 +190,5 @@ async fn empty(ctx: TestCtx) { .await .unwrap(); - assert_eq!(res.errors.len(), 22, "validation failed"); + assert_eq!(res.errors.len(), 21, "validation failed"); } diff --git a/svc/pkg/ip/ops/info/Service.toml b/svc/pkg/ip/ops/info/Service.toml index 1a6ded9652..f73b4df2b2 100644 --- a/svc/pkg/ip/ops/info/Service.toml +++ b/svc/pkg/ip/ops/info/Service.toml @@ -6,8 +6,8 @@ kind = "rust" [operation] -[databases] -db-ip-info = {} - [secrets] "ip_info/token" = { optional = true } + +[databases] +db-ip-info = {} diff --git a/svc/pkg/ip/ops/info/src/lib.rs b/svc/pkg/ip/ops/info/src/lib.rs index 4bc9aabc24..2bc463effa 100644 --- a/svc/pkg/ip/ops/info/src/lib.rs +++ b/svc/pkg/ip/ops/info/src/lib.rs @@ -60,12 +60,24 @@ async fn fetch_ip_info_io( // Fetch IP data from external service tracing::info!(?ip_str, "fetching fresh ip info"); - let ip_info_res = reqwest::get(api_url).await?; + + let client = reqwest::Client::new(); + let req = client.get(format!("https://ipinfo.io/{}", ip_str)); + + let req = if let Ok(token) = util::env::read_secret(&["ip_info", "token"]).await { + req.query(&[("token", token)]) + } else { + req + }; + + let ip_info_res = req.send().await?; if !ip_info_res.status().is_success() { - tracing::error!(status = ?ip_info_res.status(), "failed to fetch ip info, using fallback"); + let status = ip_info_res.status(); + let body = ip_info_res.text().await?; + tracing::error!(?status, %body, "failed to fetch ip info"); - bail!("ip info error") + bail!("ip info error"); }; let ip_info_raw = ip_info_res.json::().await?; diff --git a/svc/pkg/job-run/worker/tests/stop.rs b/svc/pkg/job-run/worker/tests/stop.rs index 8c64769ac3..71d849dec6 100644 --- a/svc/pkg/job-run/worker/tests/stop.rs +++ b/svc/pkg/job-run/worker/tests/stop.rs @@ -2,7 +2,7 @@ use chirp_worker::prelude::*; use proto::backend::pkg::*; #[worker_test] -async fn empty(ctx: TestCtx) { +async fn stop(ctx: TestCtx) { if !util::feature::job_run() { return; } @@ -70,9 +70,8 @@ async fn empty(ctx: TestCtx) { .task_states .as_ref() .unwrap() - .get("test-server") - .expect("missing test-server task state"); - tracing::info!(?task_state, "task state"); + .get("main") + .expect("missing main task state"); assert!(!task_state.failed.unwrap(), "task failed"); assert_eq!("stop", status.desired_status.as_ref().unwrap()); assert_eq!("dead", task_state.state.as_ref().unwrap());