Skip to content

Commit

Permalink
fix: game, ip, and job tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Mar 21, 2024
1 parent 862cfe3 commit 0f867bf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions lib/util/core/src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ pub fn fly() -> bool {
pub fn job_run() -> bool {
std::env::var("RIVET_HAS_POOLS").ok().is_some()
}

pub fn billing() -> bool {
std::env::var("RIVET_BILLING").ok().is_some()
}
7 changes: 5 additions & 2 deletions svc/pkg/game/ops/namespace-get/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion svc/pkg/game/ops/version-validate/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
3 changes: 3 additions & 0 deletions svc/pkg/ip/ops/info/Service.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ kind = "rust"

[operation]

[secrets]
"ip_info/token" = { optional = true }

[databases]
db-ip-info = {}
25 changes: 16 additions & 9 deletions svc/pkg/ip/ops/info/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use proto::backend::{self, pkg::*};
use rivet_operation::prelude::*;

const IP_INFO_TOKEN: &str = "1a0c0cea381431";

/// Parsed response from ipinfo.io. We can't retrieve data from bogon or anycast
/// addresses.
#[derive(serde::Deserialize)]
Expand Down Expand Up @@ -55,16 +53,25 @@ async fn fetch_ip_info_io(
} else {
// Fetch IP data from external service
tracing::info!(?ip_str, "fetching fresh ip info");
let ip_info_res = reqwest::get(format!(
"https://ipinfo.io/{}?token={}",
ip_str, IP_INFO_TOKEN
))
.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(&["rivet", "api_route", "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::<serde_json::Value>().await?;
Expand Down
7 changes: 3 additions & 4 deletions svc/pkg/job-run/worker/tests/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 0f867bf

Please sign in to comment.