Skip to content

Commit 12411e1

Browse files
committed
test: Added test on repos
1 parent 49f4570 commit 12411e1

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/protocol/v7.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,10 @@ pub struct RepoReference {
419419
pub name: String,
420420
/// The optional prefix path to apply to source code when pairing it
421421
/// up with files in the repository.
422+
#[serde(skip_serializing_if = "Option::is_none")]
422423
pub prefix: Option<String>,
423424
/// The optional current revision of the local repository.
425+
#[serde(skip_serializing_if = "Option::is_none")]
424426
pub revision: Option<String>,
425427
}
426428

tests/test_protocol_v7.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ extern crate serde;
33
extern crate serde_json;
44
extern crate uuid;
55

6+
use std::collections::HashMap;
7+
68
use sentry_types::protocol::v7;
79

810
fn reserialize(event: &v7::Event) -> v7::Event {
@@ -125,6 +127,61 @@ fn test_logentry_basics() {
125127
);
126128
}
127129

130+
#[test]
131+
fn test_modules() {
132+
let event = v7::Event {
133+
modules: {
134+
let mut m = HashMap::new();
135+
m.insert("System".into(), "1.0.0".into());
136+
m
137+
},
138+
..Default::default()
139+
};
140+
assert_eq!(
141+
serde_json::to_string(&event).unwrap(),
142+
"{\"modules\":{\"System\":\"1.0.0\"}}"
143+
);
144+
}
145+
146+
#[test]
147+
fn test_repos() {
148+
let event = v7::Event {
149+
repos: {
150+
let mut m = HashMap::new();
151+
m.insert("/raven".into(), v7::RepoReference {
152+
name: "github/raven".into(),
153+
prefix: Some("/".into()),
154+
revision: Some("49f45700b5fe606c1bcd9bf0205ecbb83db17f52".into()),
155+
});
156+
m
157+
},
158+
..Default::default()
159+
};
160+
161+
assert_eq!(
162+
serde_json::to_string(&event).unwrap(),
163+
"{\"repos\":{\"/raven\":{\"name\":\"github/raven\",\"prefix\":\"/\",\"revision\":\"49f45700b5fe606c1bcd9bf0205ecbb83db17f52\"}}}"
164+
);
165+
166+
let event = v7::Event {
167+
repos: {
168+
let mut m = HashMap::new();
169+
m.insert("/raven".into(), v7::RepoReference {
170+
name: "github/raven".into(),
171+
prefix: None,
172+
revision: None,
173+
});
174+
m
175+
},
176+
..Default::default()
177+
};
178+
179+
assert_eq!(
180+
serde_json::to_string(&event).unwrap(),
181+
"{\"repos\":{\"/raven\":{\"name\":\"github/raven\"}}}"
182+
);
183+
}
184+
128185
#[test]
129186
fn test_canonical_exception() {
130187
let mut event: v7::Event = Default::default();

0 commit comments

Comments
 (0)