Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ with_crash_reporting = []
allow-attributes = "warn"
str-to-string = "warn"
string-to-string = "warn"
tests-outside-test-module = "warn"
unnecessary-wraps = "warn"
uninlined-format-args = "warn"
unused-trait-names = "warn"
Expand Down
11 changes: 8 additions & 3 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,12 @@ pub fn main() -> ! {
process::exit(exit_code);
}

#[test]
fn verify_app() {
app().debug_assert();
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn verify_app() {
app().debug_assert();
}
}
95 changes: 50 additions & 45 deletions src/commands/sourcemaps/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,52 +467,57 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
Ok(())
}

#[test]
fn test_resolve_sourcemap_url() {
// Tests coming from `tests/sentry/utils/test_urls.py` in `getsentry/sentry`
let cases = vec![
("http://example.com/foo", "bar", "http://example.com/bar"),
("http://example.com/foo", "/bar", "http://example.com/bar"),
("https://example.com/foo", "/bar", "https://example.com/bar"),
(
"http://example.com/foo/baz",
"bar",
"http://example.com/foo/bar",
),
(
"http://example.com/foo/baz",
"/bar",
"http://example.com/bar",
),
("aps://example.com/foo", "/bar", "aps://example.com/bar"),
(
"apsunknown://example.com/foo",
"/bar",
"apsunknown://example.com/bar",
),
(
"apsunknown://example.com/foo",
"//aha/uhu",
"apsunknown://aha/uhu",
),
];

for (base, to_join, expected) in cases {
assert_eq!(resolve_sourcemap_url(base, to_join).unwrap(), expected);
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_resolve_sourcemap_url() {
// Tests coming from `tests/sentry/utils/test_urls.py` in `getsentry/sentry`
let cases = vec![
("http://example.com/foo", "bar", "http://example.com/bar"),
("http://example.com/foo", "/bar", "http://example.com/bar"),
("https://example.com/foo", "/bar", "https://example.com/bar"),
(
"http://example.com/foo/baz",
"bar",
"http://example.com/foo/bar",
),
(
"http://example.com/foo/baz",
"/bar",
"http://example.com/bar",
),
("aps://example.com/foo", "/bar", "aps://example.com/bar"),
(
"apsunknown://example.com/foo",
"/bar",
"apsunknown://example.com/bar",
),
(
"apsunknown://example.com/foo",
"//aha/uhu",
"apsunknown://aha/uhu",
),
];

for (base, to_join, expected) in cases {
assert_eq!(resolve_sourcemap_url(base, to_join).unwrap(), expected);
}
}
}

#[test]
fn test_unify_artifact_url() {
let cases = vec![
(
"http://localhost:5000/dist/bundle.min.js",
"~/dist/bundle.min.js",
),
("/dist/bundle.js.map", "~/dist/bundle.js.map"),
];

for (path, expected) in cases {
assert_eq!(unify_artifact_url(path).unwrap(), expected);
#[test]
fn test_unify_artifact_url() {
let cases = vec![
(
"http://localhost:5000/dist/bundle.min.js",
"~/dist/bundle.min.js",
),
("/dist/bundle.js.map", "~/dist/bundle.js.map"),
];

for (path, expected) in cases {
assert_eq!(unify_artifact_url(path).unwrap(), expected);
}
}
}
75 changes: 40 additions & 35 deletions src/utils/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,40 +72,45 @@ pub fn is_absolute_url(url: &str) -> bool {
url.starts_with("http://") || url.starts_with("https://")
}

#[test]
fn test_parse_link_header() {
let rv = parse_link_header("<https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1>; rel=\"previous\"; results=\"false\"; cursor=\"100:-1:1\", <https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0>; rel=\"next\"; results=\"true\"; cursor=\"100:1:0\"");
assert_eq!(rv.len(), 2);

let a = &rv[0];
let b = &rv[1];

assert_eq!(
a.get("_link").unwrap(),
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1"
);
assert_eq!(a.get("cursor").unwrap(), &"100:-1:1");
assert_eq!(a.get("rel").unwrap(), &"previous");
assert_eq!(a.get("results").unwrap(), &"false");

assert_eq!(
b.get("_link").unwrap(),
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0"
);
assert_eq!(b.get("cursor").unwrap(), &"100:1:0");
assert_eq!(b.get("rel").unwrap(), &"next");
assert_eq!(b.get("results").unwrap(), &"true");
}
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_parse_link_header() {
let rv = parse_link_header("<https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1>; rel=\"previous\"; results=\"false\"; cursor=\"100:-1:1\", <https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0>; rel=\"next\"; results=\"true\"; cursor=\"100:1:0\"");
assert_eq!(rv.len(), 2);

let a = &rv[0];
let b = &rv[1];

assert_eq!(
a.get("_link").unwrap(),
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1"
);
assert_eq!(a.get("cursor").unwrap(), &"100:-1:1");
assert_eq!(a.get("rel").unwrap(), &"previous");
assert_eq!(a.get("results").unwrap(), &"false");

#[test]
fn test_is_absolute_url() {
assert!(is_absolute_url("https://sentry.io"));
assert!(is_absolute_url("http://sentry.io"));
assert!(is_absolute_url("https://sentry.io/path"));
assert!(is_absolute_url("http://sentry.io/path"));
assert!(is_absolute_url("http://sentry.io/path?query=foo"));
assert!(is_absolute_url("https://sentry.io/path?query=foo"));

assert!(!is_absolute_url("/path"));
assert!(!is_absolute_url("/path?query=foo"));
assert_eq!(
b.get("_link").unwrap(),
&"https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0"
);
assert_eq!(b.get("cursor").unwrap(), &"100:1:0");
assert_eq!(b.get("rel").unwrap(), &"next");
assert_eq!(b.get("results").unwrap(), &"true");
}

#[test]
fn test_is_absolute_url() {
assert!(is_absolute_url("https://sentry.io"));
assert!(is_absolute_url("http://sentry.io"));
assert!(is_absolute_url("https://sentry.io/path"));
assert!(is_absolute_url("http://sentry.io/path"));
assert!(is_absolute_url("http://sentry.io/path?query=foo"));
assert!(is_absolute_url("https://sentry.io/path?query=foo"));

assert!(!is_absolute_url("/path"));
assert!(!is_absolute_url("/path?query=foo"));
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to snapshot testing used in this crate (it is called insta in case you are interested).

Since we moved the functions into a different module, the file names need to be updated. For most of the files, it was a simple rename, but for this one, the expression on line 3 appears to have had some changes, so git recognized it as a deletion of this file, and an adding of the file with the new path

Copy link
Copy Markdown
Member

@lcian lcian Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I was wondering why the tests would fail with this.
Yeah I saw insta and I think we should use it in the SDK too, I have an issue here getsentry/sentry-rust#875

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly had no clue what insta was before doing this PR and seeing these failures in CI. We don't use it very widely in Sentry CLI. Maybe we should; although, I admittedly am unsure what it is useful for. I only did the minimal amount of research on it to fix the tests and move on 🤷

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: src/utils/vcs.rs
expression: "commits.0.iter().map(|c|\n{\n (c.author().name().unwrap().to_owned(),\n c.author().email().unwrap().to_owned(), c.summary(),)\n}).collect::<Vec<_>>()"
---
[
(
"John Doe",
"john.doe@example.com",
Some(
"\"second commit\"",
),
),
(
"John Doe",
"john.doe@example.com",
Some(
"\"initial commit\"",
),
),
]
Loading
Loading