Skip to content

Commit

Permalink
ref(test): Rename EndpointOptions to MockEndpointBuilder
Browse files Browse the repository at this point in the history
The new name describes more accurately what the struct now does.
  • Loading branch information
szokeasaurusrex committed Nov 14, 2024
1 parent 0192350 commit ec37742
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 136 deletions.
28 changes: 14 additions & 14 deletions tests/integration/debug_files/upload.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use assert_cmd::Command;

use crate::integration::{mock_endpoint, register_test, test_utils::env, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, test_utils::env, MockEndpointBuilder};

#[test]
fn command_debug_files_upload() {
let _chunk_upload = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
Expand All @@ -22,11 +22,11 @@ fn command_debug_files_upload() {
#[test]
fn command_debug_files_upload_pdb() {
let _chunk_upload = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
Expand All @@ -47,11 +47,11 @@ fn command_debug_files_upload_pdb() {
#[test]
fn command_debug_files_upload_pdb_embedded_sources() {
let _chunk_upload = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
Expand All @@ -71,11 +71,11 @@ fn command_debug_files_upload_pdb_embedded_sources() {
#[test]
fn command_debug_files_upload_dll_embedded_ppdb_with_sources() {
let _chunk_upload = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
Expand All @@ -95,11 +95,11 @@ fn command_debug_files_upload_dll_embedded_ppdb_with_sources() {
#[test]
fn command_debug_files_upload_mixed_embedded_sources() {
let _chunk_upload = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
Expand All @@ -123,11 +123,11 @@ fn command_debug_files_upload_mixed_embedded_sources() {
#[test]
fn command_debug_files_upload_no_upload() {
let _chunk_upload = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
Expand All @@ -143,7 +143,7 @@ fn command_debug_files_upload_no_upload() {
/// are already uploaded.
fn ensure_correct_assemble_call() {
let _chunk_upload = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/deploys/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn command_deploys_list() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"GET",
"/api/0/organizations/wat-org/releases/wat-release/deploys/",
200,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/deploys/new.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use mockito::Matcher;
use serde_json::json;

use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn command_deploys_new() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/organizations/wat-org/releases/wat-release/deploys/",
200,
Expand All @@ -23,7 +23,7 @@ fn command_deploys_new() {
#[test]
fn command_releases_deploys_new() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"POST",
"/api/0/organizations/wat-org/releases/wat-release/deploys/",
200,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/events.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::integration::register_test;

use super::{mock_endpoint, EndpointOptions};
use super::{mock_endpoint, MockEndpointBuilder};

#[test]
fn command_events() {
// Mock server is used only for the events/events-list-empty.trycmd
// test. No harm in leaving it here for other tests.
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"GET",
"/api/0/projects/wat-org/wat-project/events/?cursor=",
200,
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use mockito::server_url;
use trycmd::TestCases;

use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn command_info_help() {
Expand All @@ -28,7 +28,7 @@ fn command_info_no_token_backtrace() {
#[test]
fn command_info_basic() {
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
MockEndpointBuilder::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
);
let t = register_test("info/info-basic.trycmd");
t.insert_var("[SERVER]", server_url()).unwrap();
Expand All @@ -37,7 +37,7 @@ fn command_info_basic() {
#[test]
fn command_info_no_defaults() {
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
MockEndpointBuilder::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
);
let t = register_test("info/info-json.trycmd");
t.insert_var("[SERVER]", server_url()).unwrap();
Expand All @@ -46,7 +46,7 @@ fn command_info_no_defaults() {
#[test]
fn command_info_json() {
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
MockEndpointBuilder::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
);
let t = register_test("info/info-basic.trycmd");
t.insert_var("[SERVER]", server_url()).unwrap();
Expand All @@ -55,7 +55,7 @@ fn command_info_json() {
#[test]
fn command_info_json_without_defaults() {
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
MockEndpointBuilder::new("GET", "/api/0/", 200).with_response_file("info/get-info.json"),
);
let t = register_test("info/info-json-no-defaults.trycmd");
t.env("SENTRY_ORG", "").env("SENTRY_PROJECT", "");
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/issues/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn command_issues_list_help() {
Expand All @@ -8,7 +8,7 @@ fn command_issues_list_help() {
#[test]
fn doesnt_fail_with_empty_response() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"GET",
"/api/0/projects/wat-org/wat-project/issues/?query=&cursor=",
200,
Expand All @@ -21,7 +21,7 @@ fn doesnt_fail_with_empty_response() {
#[test]
fn display_issues() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"GET",
"/api/0/projects/wat-org/wat-project/issues/?query=&cursor=",
200,
Expand All @@ -34,7 +34,7 @@ fn display_issues() {
#[test]
fn display_resolved_issues() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"GET",
"/api/0/projects/wat-org/wat-project/issues/?query=is:resolved&cursor=",
200,
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use mockito::{self, server_url, Mock};
use trycmd::TestCases;

use test_utils::env;
use test_utils::{mock_endpoint, EndpointOptions};
use test_utils::{mock_endpoint, MockEndpointBuilder};

pub const UTC_DATE_FORMAT: &str = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6,9}Z";
const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -138,21 +138,21 @@ pub fn mock_common_upload_endpoints(

vec![
mock_endpoint(
EndpointOptions::new("POST", "/api/0/projects/wat-org/wat-project/releases/", 208)
MockEndpointBuilder::new("POST", "/api/0/projects/wat-org/wat-project/releases/", 208)
.with_response_file("releases/get-release.json"),
)
.expect_at_least(release_request_count)
.expect_at_most(release_request_count),
mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_body(chunk_upload_response),
),
mock_endpoint(
EndpointOptions::new("POST", "/api/0/organizations/wat-org/chunk-upload/", 200)
MockEndpointBuilder::new("POST", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_body("[]"),
),
mock_endpoint(
EndpointOptions::new("POST", assemble_endpoint, 200).with_response_body(format!(
MockEndpointBuilder::new("POST", assemble_endpoint, 200).with_response_body(format!(
r#"{{"state":"created","missingChunks":{}}}"#,
serde_json::to_string(&missing_chunks).unwrap()
)),
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/monitors.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn command_monitors() {
let _list_endpoint = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/monitors/?cursor=", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/monitors/?cursor=", 200)
.with_response_file("monitors/get-monitors.json"),
);
let _envelope_endpoint =
mock_endpoint(EndpointOptions::new("POST", "/api/1337/envelope/", 200));
mock_endpoint(MockEndpointBuilder::new("POST", "/api/1337/envelope/", 200));
let _token_endpoint = mock_endpoint(
EndpointOptions::new("POST", "/api/0/monitors/foo-monitor/checkins/", 200)
MockEndpointBuilder::new("POST", "/api/0/monitors/foo-monitor/checkins/", 200)
.with_response_file("monitors/post-monitors.json"),
);

Expand All @@ -24,7 +24,7 @@ fn command_monitors() {

#[test]
fn command_monitors_run_server_error() {
let _server = mock_endpoint(EndpointOptions::new("POST", "/api/1337/envelope/", 500));
let _server = mock_endpoint(MockEndpointBuilder::new("POST", "/api/1337/envelope/", 500));

#[cfg(not(windows))]
register_test("monitors/server_error/monitors-run-server-error.trycmd");
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/organizations.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use mockito::server_url;

use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn command_organizations() {
// Mocks are for the organizations list command.
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/?cursor=", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/?cursor=", 200)
.with_response_file("organizations/get-organizations.json"),
);

Expand All @@ -21,7 +21,7 @@ fn command_organizations() {
);

let _mock_regions = mock_endpoint(
EndpointOptions::new("GET", "/api/0/users/me/regions/", 200)
MockEndpointBuilder::new("GET", "/api/0/users/me/regions/", 200)
.with_response_body(region_response),
);
register_test("organizations/*.trycmd");
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/projects.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn command_projects_list() {
// mock for projects list
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/organizations/wat-org/projects/?cursor=", 200)
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/projects/?cursor=", 200)
.with_response_file("projects/get-projects.json"),
);
register_test("projects/*.trycmd");
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/releases/delete.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};

#[test]
fn successfully_deletes() {
let _server = mock_endpoint(EndpointOptions::new(
let _server = mock_endpoint(MockEndpointBuilder::new(
"DELETE",
"/api/0/projects/wat-org/wat-project/releases/wat-release/",
204,
Expand All @@ -12,7 +12,7 @@ fn successfully_deletes() {

#[test]
fn allows_for_release_to_start_with_hyphen() {
let _server = mock_endpoint(EndpointOptions::new(
let _server = mock_endpoint(MockEndpointBuilder::new(
"DELETE",
"/api/0/projects/wat-org/wat-project/releases/-hyphenated-release/",
204,
Expand All @@ -22,7 +22,7 @@ fn allows_for_release_to_start_with_hyphen() {

#[test]
fn informs_about_nonexisting_releases() {
let _server = mock_endpoint(EndpointOptions::new(
let _server = mock_endpoint(MockEndpointBuilder::new(
"DELETE",
"/api/0/projects/wat-org/wat-project/releases/whoops/",
404,
Expand All @@ -33,7 +33,7 @@ fn informs_about_nonexisting_releases() {
#[test]
fn doesnt_allow_to_delete_active_releases() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"DELETE",
"/api/0/projects/wat-org/wat-project/releases/wat-release/",
400,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/releases/finalize.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::integration::{mock_endpoint, register_test, EndpointOptions};
use crate::integration::{mock_endpoint, register_test, MockEndpointBuilder};
use mockito::Matcher;
use serde_json::json;

#[test]
fn successfully_creates_a_release() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"PUT",
"/api/0/projects/wat-org/wat-project/releases/wat-release/",
200,
Expand All @@ -18,7 +18,7 @@ fn successfully_creates_a_release() {
#[test]
fn allows_for_release_to_start_with_hyphen() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"PUT",
"/api/0/projects/wat-org/wat-project/releases/-hyphenated-release/",
200,
Expand All @@ -31,7 +31,7 @@ fn allows_for_release_to_start_with_hyphen() {
#[test]
fn release_with_custom_dates() {
let _server = mock_endpoint(
EndpointOptions::new(
MockEndpointBuilder::new(
"PUT",
"/api/0/projects/wat-org/wat-project/releases/wat-release/",
200,
Expand Down
Loading

0 comments on commit ec37742

Please sign in to comment.