From 12411e18916f027c9184bd19d0ae59a1bd2e6117 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 23 Mar 2018 23:48:53 +0100 Subject: [PATCH] test: Added test on repos --- src/protocol/v7.rs | 2 ++ tests/test_protocol_v7.rs | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/protocol/v7.rs b/src/protocol/v7.rs index cf1e994f..f83d85fa 100644 --- a/src/protocol/v7.rs +++ b/src/protocol/v7.rs @@ -419,8 +419,10 @@ pub struct RepoReference { pub name: String, /// The optional prefix path to apply to source code when pairing it /// up with files in the repository. + #[serde(skip_serializing_if = "Option::is_none")] pub prefix: Option, /// The optional current revision of the local repository. + #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, } diff --git a/tests/test_protocol_v7.rs b/tests/test_protocol_v7.rs index 6e28bcfb..039f1077 100644 --- a/tests/test_protocol_v7.rs +++ b/tests/test_protocol_v7.rs @@ -3,6 +3,8 @@ extern crate serde; extern crate serde_json; extern crate uuid; +use std::collections::HashMap; + use sentry_types::protocol::v7; fn reserialize(event: &v7::Event) -> v7::Event { @@ -125,6 +127,61 @@ fn test_logentry_basics() { ); } +#[test] +fn test_modules() { + let event = v7::Event { + modules: { + let mut m = HashMap::new(); + m.insert("System".into(), "1.0.0".into()); + m + }, + ..Default::default() + }; + assert_eq!( + serde_json::to_string(&event).unwrap(), + "{\"modules\":{\"System\":\"1.0.0\"}}" + ); +} + +#[test] +fn test_repos() { + let event = v7::Event { + repos: { + let mut m = HashMap::new(); + m.insert("/raven".into(), v7::RepoReference { + name: "github/raven".into(), + prefix: Some("/".into()), + revision: Some("49f45700b5fe606c1bcd9bf0205ecbb83db17f52".into()), + }); + m + }, + ..Default::default() + }; + + assert_eq!( + serde_json::to_string(&event).unwrap(), + "{\"repos\":{\"/raven\":{\"name\":\"github/raven\",\"prefix\":\"/\",\"revision\":\"49f45700b5fe606c1bcd9bf0205ecbb83db17f52\"}}}" + ); + + let event = v7::Event { + repos: { + let mut m = HashMap::new(); + m.insert("/raven".into(), v7::RepoReference { + name: "github/raven".into(), + prefix: None, + revision: None, + }); + m + }, + ..Default::default() + }; + + assert_eq!( + serde_json::to_string(&event).unwrap(), + "{\"repos\":{\"/raven\":{\"name\":\"github/raven\"}}}" + ); +} + #[test] fn test_canonical_exception() { let mut event: v7::Event = Default::default();