Skip to content

Commit

Permalink
CI gate IPIINFO test
Browse files Browse the repository at this point in the history
  • Loading branch information
durch committed Dec 12, 2024
1 parent 3bb3f5b commit b136b79
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions nym-node-status-api/nym-node-status-api/src/monitor/geodata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,31 +154,39 @@ mod api_regression {
use super::*;
use std::{env::var, sync::LazyLock};

static IPINFO_TOKEN: LazyLock<String> = LazyLock::new(|| var("IPINFO_API_TOKEN").unwrap());
static IPINFO_TOKEN: LazyLock<Option<String>> = LazyLock::new(|| var("IPINFO_API_TOKEN").ok());
static CI: LazyLock<Option<String>> = LazyLock::new(|| var("CI").ok());

#[tokio::test]
async fn should_parse_response() {
let client = IpInfoClient::new(&(*IPINFO_TOKEN));
let my_ip = reqwest::get("https://api.ipify.org")
.await
.expect("Couldn't get own IP")
.text()
.await
.unwrap();

let location_result = client.locate_ip(my_ip).await;
assert!(location_result.is_ok(), "Did ipinfo response change?");

assert!(
client.check_remaining_bandwidth().await.is_ok(),
"Failed to check remaining bandwidth?"
);

// when serialized, these fields should be present because they're exposed over API
let location_result = location_result.unwrap();
let json = serde_json::to_value(&location_result).unwrap();
assert!(json.get("two_letter_iso_country_code").is_some());
assert!(json.get("latitude").is_some());
assert!(json.get("longitude").is_some());
if let Some(token) = &*IPINFO_TOKEN {
if CI.is_none() {
return;
}
let client = IpInfoClient::new(token);
let my_ip = reqwest::get("https://api.ipify.org")
.await
.expect("Couldn't get own IP")
.text()
.await
.unwrap();

let location_result = client.locate_ip(my_ip).await;
assert!(location_result.is_ok(), "Did ipinfo response change?");

assert!(
client.check_remaining_bandwidth().await.is_ok(),
"Failed to check remaining bandwidth?"
);

// when serialized, these fields should be present because they're exposed over API
let location_result = location_result.unwrap();
let json = serde_json::to_value(&location_result).unwrap();
assert!(json.get("two_letter_iso_country_code").is_some());
assert!(json.get("latitude").is_some());
assert!(json.get("longitude").is_some());
} else {
panic!("IPINFO_API_TOKEN not set");
}
}
}

0 comments on commit b136b79

Please sign in to comment.