-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
test_client.rs
81 lines (68 loc) · 2.19 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#![cfg(feature = "test")]
use std::panic;
use std::sync::Arc;
#[test]
fn test_into_client() {
let c: sentry::Client = sentry::Client::from_config("https://public@example.com/42%21");
{
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%21");
}
let c: sentry::Client = sentry::Client::from_config((
"https://public@example.com/42%21",
sentry::ClientOptions {
release: Some("foo@1.0".into()),
..Default::default()
},
));
{
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%21");
assert_eq!(&c.options().release.as_ref().unwrap(), &"foo@1.0");
}
assert!(sentry::Client::from_config(()).options().dsn.is_none());
}
#[test]
fn test_unwind_safe() {
let transport = sentry::test::TestTransport::new();
let options = sentry::ClientOptions {
dsn: Some("https://public@example.com/1".parse().unwrap()),
transport: Some(Arc::new(transport.clone())),
..sentry::ClientOptions::default()
};
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);
}
#[test]
fn test_concurrent_init() {
let _guard = sentry::init(sentry::ClientOptions {
..Default::default()
});
std::thread::spawn(|| {
let _guard = sentry::init(sentry::ClientOptions {
..Default::default()
});
})
.join()
.unwrap();
}
#[test]
fn test_invalid_proxy() {
let _guard = sentry::init(sentry::ClientOptions {
https_proxy: Some("".into()),
..Default::default()
});
}