Skip to content

Commit ba60b84

Browse files
committed
fix: failing test
1 parent 539d4ea commit ba60b84

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

tests/telemetry_tests.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
mod tests {
33
use gitops_operator::telemetry::{init_subscriber, resource};
44
use opentelemetry::global;
5-
use opentelemetry_semantic_conventions::resource::SERVICE_NAME;
6-
use opentelemetry_semantic_conventions::resource::SERVICE_VERSION;
75
use std::sync::Once;
86
use std::time::Duration;
97
use tokio::time::timeout;
@@ -16,6 +14,7 @@ mod tests {
1614
init_subscriber("test-telemetry".into(), "debug".into());
1715
});
1816
}
17+
1918
// Helper function to set up a test environment
2019
async fn setup_test_environment() {
2120
// Small delay to ensure cleanup is complete
@@ -32,14 +31,45 @@ mod tests {
3231
}
3332
}
3433

35-
// #[tokio::test(flavor = "multi_thread")]
36-
#[tokio::test()]
34+
#[tokio::test(flavor = "multi_thread")]
3735
async fn test_resource_creation() {
3836
let resource = resource("gitops-operator".into());
3937
let attributes = resource.iter().collect::<Vec<_>>();
4038

41-
assert!(attributes.iter().any(|kv| kv.0.as_str() == SERVICE_NAME));
42-
assert!(attributes.iter().any(|kv| kv.1.as_str() == SERVICE_VERSION));
39+
// Print resource for debugging
40+
println!("Resource: {:?}", resource);
41+
42+
// Check for service name
43+
let has_service_name = attributes.iter().any(|(k, _)| k.as_str() == "SERVICE_NAME");
44+
println!("Has SERVICE_NAME: {}", has_service_name);
45+
46+
// Check for service version
47+
let has_service_version = attributes
48+
.iter()
49+
.any(|(k, _)| k.as_str() == "SERVICE_VERSION");
50+
println!("Has SERVICE_VERSION: {}", has_service_version);
51+
52+
assert!(has_service_name, "SERVICE_NAME attribute not found");
53+
assert!(has_service_version, "SERVICE_VERSION attribute not found");
54+
55+
// Also check the values if needed
56+
let service_name_value = attributes
57+
.iter()
58+
.find(|(k, _)| k.as_str() == "SERVICE_NAME")
59+
.map(|(_, v)| v.to_string());
60+
println!("SERVICE_NAME value: {:?}", service_name_value);
61+
62+
let service_version_value = attributes
63+
.iter()
64+
.find(|(k, _)| k.as_str() == "SERVICE_VERSION")
65+
.map(|(_, v)| v.to_string());
66+
println!("SERVICE_VERSION value: {:?}", service_version_value);
67+
68+
assert_eq!(service_name_value, Some("gitops-operator".to_string()));
69+
assert_eq!(
70+
service_version_value,
71+
Some(env!("CARGO_PKG_VERSION").to_string())
72+
);
4373
}
4474

4575
#[tokio::test(flavor = "multi_thread")]

0 commit comments

Comments
 (0)