Skip to content

Commit

Permalink
chore: add datacenter location get test
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Apr 17, 2024
1 parent 1ff737c commit e03d657
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
74 changes: 73 additions & 1 deletion svc/pkg/cluster/ops/datacenter-location-get/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,78 @@
use chirp_worker::prelude::*;
use proto::backend::{self, pkg::*};

#[worker_test]
async fn basic(ctx: TestCtx) {
// TODO:
let datacenter_id = Uuid::new_v4();
let cluster_id = Uuid::new_v4();
let server_id = Uuid::new_v4();

msg!([ctx] cluster::msg::create(cluster_id) -> cluster::msg::create_complete {
cluster_id: Some(cluster_id.into()),
name_id: util::faker::ident(),
owner_team_id: None,
})
.await
.unwrap();

msg!([ctx] cluster::msg::datacenter_create(datacenter_id) -> cluster::msg::datacenter_scale {
datacenter_id: Some(datacenter_id.into()),
cluster_id: Some(cluster_id.into()),
name_id: util::faker::ident(),
display_name: util::faker::ident(),

provider: backend::cluster::Provider::Linode as i32,
provider_datacenter_id: "us-southeast".to_string(),
provider_api_token: None,

pools: Vec::new(),

build_delivery_method: backend::cluster::BuildDeliveryMethod::TrafficServer as i32,
drain_timeout: 0,
})
.await
.unwrap();

// Insert fake server record
sql_execute!(
[ctx]
"
INSERT INTO db_cluster.servers (
server_id,
datacenter_id,
cluster_id,
pool_type,
create_ts,
public_ip
)
VALUES ($1, $2, $3, $4, $5, $6)
",
server_id,
datacenter_id,
cluster_id,
backend::cluster::PoolType::Gg as i64,
util::timestamp::now(),
// Google
"172.217.12.110",
)
.await
.unwrap();

let locations_res = op!([ctx] cluster_datacenter_location_get {
datacenter_ids: vec![datacenter_id.into()],
})
.await
.unwrap();

assert_eq!(
1,
locations_res.datacenters.len(),
"wrong number of locations"
);

let location = locations_res.datacenters.first().unwrap();
let coords = location.coords.as_ref().unwrap();

assert_eq!(37.3394, coords.latitude);
assert_eq!(-121.8950, coords.longitude);
}
1 change: 1 addition & 0 deletions svc/pkg/cluster/util/gen/hash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
80b6ae8f1c15377d4c11bbb28a5705b982c8ac92

0 comments on commit e03d657

Please sign in to comment.