use ddog::prelude::*;
extern crate dotenv;
use dotenv::dotenv;
#[test]
fn create_new_tag_explicitly() {
dotenv().ok();
let api_key = dotenv::var("DD_API_KEY").unwrap();
let application_key = dotenv::var("DD_APPLICATION_KEY").unwrap();
let mut builder = builder::Builder::new();
let mut builder_ref = builder.v2();
if dotenv::var("TRACING_SUBSCRIBER")
.map(|s| s == "true")
.unwrap_or(false)
{
builder_ref = builder_ref.with_subscriber();
}
tokio_test::block_on(async {
let (status, res) = builder_ref
.create_new_tag_config("rpc_latency")
.headers(vec![
("Accept", "application/json"),
("Content-Type", "application/json"),
("DD-API-KEY", &api_key),
("DD-APPLICATION-KEY", &application_key),
])
.body(
r#"{
"data": {
"type": "manage_tags",
"id": "CreateGridfinTag2",
"attributes": {
"tags": [ "gridfin" ],
"metric_type": "count"
}
}
}"#,
)
.execute()
.await;
tracing::info!(target: "v2/metrics/{}/tags", "Response: {:?}", res);
tracing::info!(target: "v2/metrics/{}/tags", "Response: {:?}", status);
});
}
#[test]
fn create_new_tag_forbidden_key() {
let mut builder = builder::Builder::new();
let mut builder_ref = builder.v2();
if dotenv::var("TRACING_SUBSCRIBER")
.map(|s| s == "true")
.unwrap_or(false)
{
builder_ref = builder_ref.with_subscriber();
}
tokio_test::block_on(async {
let (status, res) = builder_ref
.create_new_tag_config("rpc_latency")
.headers(vec![
("Accept", "application/json"),
("Content-Type", "application/json"),
("DD-API-KEY", "RANDOM_API_KEY.JPEG"),
("DD-APPLICATION-KEY", "RANDOM_APPLICATION_KEY.JPEG"),
])
.body(
r#"{
"data": {
"type": "manage_tags",
"id": "CreateGridfinTag2",
"attributes": {
"tags": [ "gridfin" ],
"metric_type": "count"
}
}
}"#,
)
.execute()
.await;
tracing::info!(target: "v2/series", "Response: {:?}", res);
assert_eq!(status, 403);
});
}