-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtest_client.rs
54 lines (44 loc) · 1.65 KB
/
test_client.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![cfg(feature = "test")]
use std::panic;
use std::sync::Arc;
#[test]
fn test_into_client() {
let c: sentry::Client = sentry::Client::from_config("https://[email protected]/42");
{
let dsn = c.dsn().unwrap();
assert_eq!(dsn.public_key(), "public");
assert_eq!(dsn.host(), "example.com");
assert_eq!(dsn.scheme(), sentry::types::Scheme::Https);
assert_eq!(dsn.project_id().value(), 42);
}
let c: sentry::Client = sentry::Client::from_config((
"https://[email protected]/42",
sentry::ClientOptions::configure(|o| o.set_release(Some("[email protected]".into()))),
));
{
let dsn = c.dsn().unwrap();
assert_eq!(dsn.public_key(), "public");
assert_eq!(dsn.host(), "example.com");
assert_eq!(dsn.scheme(), sentry::types::Scheme::Https);
assert_eq!(dsn.project_id().value(), 42);
assert_eq!(&c.options().release().unwrap(), "[email protected]");
}
assert!(sentry::Client::from_config(()).options().dsn().is_none());
}
#[test]
fn test_unwind_safe() {
let transport = sentry::test::TestTransport::new();
let options = sentry::ClientOptions::configure(|o| {
o.set_dsn("https://[email protected]/1".parse().unwrap())
.set_transport(Arc::new(transport.clone()))
});
let client: Arc<sentry::Client> = Arc::new(options.into());
panic::catch_unwind(|| {
sentry::Hub::current().bind_client(Some(client));
sentry::capture_message("Hello World!", sentry::Level::Warning);
})
.unwrap();
sentry::Hub::current().bind_client(None);
let events = transport.fetch_and_clear_events();
assert_eq!(events.len(), 1);
}