From 886d3bf1ad92faad60e44f1f388eab6982c89d23 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Tue, 5 Nov 2024 14:49:27 +0100 Subject: [PATCH] ref: Remove `SENTRY_DUMP_REPONSE` environment variable We do not appear to use the output generated by SENTRY_DUMP_RESPONSE anywhere. The code only appears to be there for debugging/development purposes, so developers can add it back as needed. No need to ship this code to end users. --- CONTRIBUTING.md | 6 ------ src/api/mod.rs | 31 ++----------------------------- tests/integration/mod.rs | 1 - 3 files changed, 2 insertions(+), 36 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3dead760c5..d39615cab9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,9 +62,3 @@ let _assemble = mock_endpoint( .with_response_file("debug_files/post-difs-assemble.json"), ); ``` - -If you don't know what APIs will be hit during your test, register the test as normal, using `register_test` helper, -and run it in isolation, eg. `cargo test command_debug_files_upload`. -This will store all original API responses under `dump/` directory (controlled via. `SENTRY_DUMP_RESPONSES` env property set -in `tests/integration/mod`), where all path separators `/` are replaced with double underscore `__`. -This way you can simply copy the JSON files to `_responses` directory and update the data as needed. diff --git a/src/api/mod.rs b/src/api/mod.rs index da10176046..30304a6a84 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -17,12 +17,12 @@ use std::borrow::Cow; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::ffi::OsStr; -use std::fs::{create_dir_all, File}; +use std::fmt; +use std::fs::File; use std::io::{self, Read, Write}; use std::path::Path; use std::rc::Rc; use std::sync::Arc; -use std::{env, fmt}; use anyhow::{Context, Result}; use backoff::backoff::Backoff; @@ -44,7 +44,6 @@ use serde::{Deserialize, Serialize}; use sha1_smol::Digest; use symbolic::common::DebugId; use symbolic::debuginfo::ObjectKind; -use url::Url; use uuid::Uuid; use crate::api::errors::ProjectRenamedError; @@ -1841,15 +1840,6 @@ impl ApiResponse { if let Some(ref body) = self.body { let body = String::from_utf8_lossy(body); debug!("body: {}", body); - - // Internal helper for making it easier to write integration tests. - // Should not be used publicly, as it may be removed without prior warning. - // Accepts a relative or absolute path to the directory where responses should be stored. - if let Ok(dir) = env::var("SENTRY_DUMP_RESPONSES") { - if let Err(err) = dump_response(dir, &self.url, body.into_owned()) { - debug!("Could not dump a response: {}", err); - }; - } } if self.ok() { return Ok(self); @@ -1991,23 +1981,6 @@ fn log_headers(is_response: bool, data: &[u8]) { } } -fn dump_response(mut dir: String, url: &str, body: String) -> Result<()> { - if dir.starts_with('~') { - dir = format!( - "{}{}", - dirs::home_dir().unwrap_or_default().display(), - dir.trim_start_matches('~') - ); - } - let filename = Url::parse(url)?.path().trim_matches('/').replace('/', "__"); - create_dir_all(&dir)?; - let filepath = format!("{}/{}.json", &dir, filename); - let mut file = File::create(&filepath)?; - file.write_all(&body.into_bytes())?; - debug!("Response dumped to: {}", &filepath); - Ok(()) -} - #[derive(Debug, Deserialize)] #[serde(rename_all = "lowercase")] enum ErrorInfo { diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs index 095fa88b7f..628ef91c40 100644 --- a/tests/integration/mod.rs +++ b/tests/integration/mod.rs @@ -39,7 +39,6 @@ pub fn register_test_without_token(path: &str) -> TestCases { let server_addr = mockito::server_address(); test_case .env("SENTRY_INTEGRATION_TEST", "1") - .env("SENTRY_DUMP_RESPONSES", "dump") // reused default directory of `trycmd` output dumps .env("SENTRY_URL", server_url()) .env("SENTRY_ORG", "wat-org") .env("SENTRY_PROJECT", "wat-project")